[英]Counting Cumulative Occurrences and Plotting Over Time in Pandas
給定一個示例數據框,如下所示:
Time Type
2019-12-09 04:50 Exists
2019-12-08 01:20 Does Not Exist
2019-12-08 03:32 Exists
2019-12-07 01:15 APPLES
2019-12-05 04:13 Does Not Exist
我想累計計算“存在”和“不存在”的出現次數,而不是“蘋果”的出現次數,並繪制這兩個值與時間的關系圖。 我已經創建了 Occurrences,如下所示,但時間不是按升序排列的。
謝謝你。
import pandas as pd
my_cols = ["Time","Type"]
df = pd.read_csv('occurrences.txt',names = my_cols,sep=';')
df['Time'] = pd.to_datetime(df['Time'])
df.set_index('Time',inplace=True)
df['Occurrence'] = df.groupby("Type").cumcount()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.