Given a sample dataframe that looks like:
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
I want to cumulatively count the number of occurrences of "Exists" and "Does Not Exist", not the Occurrence of "APPLES", and plot those two values versus time. I have created the Occurrences, as shown below, but the time is not in ascending order.
Thank you.
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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.