1

I'm struggling with this. I've tried searching and have tried a few options but can't quite seem to manage it.

I want to take the following dataframe (simplified), which has a date_range as an index with 30 minute intervals:

                     Data
2016-11-24 00:00:00   5
2016-11-24 00:30:00   1
2016-11-24 01:00:00   4
2016-11-24 01:30:00   11
2016-11-24 02:00:00   3
2016-11-24 02:30:00   19
etc

And essentially "combine" the rows, adding the values together and changing the time series to hourly rather than 30 minute intervals, so that I end up with the following:

                     Data
2016-11-24 00:00:00   6
2016-11-24 01:00:00   15
2016-11-24 02:00:00   22
etc

Does anyone have any suggestions please?

1 Answer 1

2

You can use resample with sum:

df = df.resample('h').sum()
print (df)
                     Data
2016-11-24 00:00:00     6
2016-11-24 01:00:00    15
2016-11-24 02:00:00    22
Sign up to request clarification or add additional context in comments.

2 Comments

Wow. That was a speedy response, and that works perfectly. Thank you.
Glad can help you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.