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

Example:

Thank you.

I would be grateful for help. Thank you

Asked By: Mihai Dudnic

||

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
Answered By: Scott Boston
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.