prof31
prof31

Reputation: 85

How to rolling sum for specific intervals in time series data

I have time series data and I want to create another column that sums the value for each day. For example:

df
timestamp             val    sum
2022-10-10 00:00:00   50      50
2022-10-10 00:01:00   10      60
2022-10-10 00:02:00   20      80
...
2022-10-10 23:59:00   10     2300
2022-10-11 00:00:00   20      20
...

How can I achieve this?

Upvotes: 0

Views: 67

Answers (1)

jezrael
jezrael

Reputation: 862511

Use GroupBy.cumsum per dates:

df['sum'] = df.groupby(df['timestamp'].dt.date)['val'].cumsum()

Upvotes: 1

Related Questions