Counting events daily per year
Question:
How to count in python how many events took place in a year, increasing? ( including absent days with the number of events unchanged and summing up the events that repeat) the dates itself are events, 1 date = 1 event
Thank you.
I would be grateful for help. Thank you
Answers:
Try something like this:
df['Date'] = pd.to_datetime(df['Date'], format='%d.%m.%y')
df.groupby('Date')['value'].sum().resample('D').asfreq().fillna(0).cumsum()
Output:
Date
2021-01-01 1.0
2021-01-02 1.0
2021-01-03 1.0
2021-01-04 3.0
2021-01-05 4.0
Freq: D, Name: value, dtype: float64
How to count in python how many events took place in a year, increasing? ( including absent days with the number of events unchanged and summing up the events that repeat) the dates itself are events, 1 date = 1 event
Thank you.
I would be grateful for help. Thank you
Try something like this:
df['Date'] = pd.to_datetime(df['Date'], format='%d.%m.%y')
df.groupby('Date')['value'].sum().resample('D').asfreq().fillna(0).cumsum()
Output:
Date
2021-01-01 1.0
2021-01-02 1.0
2021-01-03 1.0
2021-01-04 3.0
2021-01-05 4.0
Freq: D, Name: value, dtype: float64