Issue
I have the following pandas DataFrame df
:
DateTime SENSOR PROD
2019-04-01 00:00:00 0 0.0
2019-04-01 00:30:00 1 10.0
2019-04-01 01:00:00 1 5.0
2019-04-01 01:30:00 1 1.0
2019-04-01 02:00:00 1 12.0
2019-04-01 02:30:00 0 0.0
The values are given at half hourly granularity. I should sum PROD
up at hourly granularity to get the following result.
DateTime PROD
2019-04-01 00:00:00 10.0
2019-04-01 01:00:00 6.0
2019-04-01 02:00:00 12.0
Solution
You can use DataFrame.resample
like so:
df.resample('H').sum()
To use resample
though, you need to make sure your index is a DatetimeIndex
. I think there are a few ways to do this, but you could try:
df.index = pd.DatetimeIndex(df.index)
Answered By - Battery_Al
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.