Reputation: 45
All,
I have a time series of data that is hourly. See below:
2014-01-01 00:00:00 96.8
2014-01-01 01:00:00 91.3
2014-01-01 02:00:00 97.8
2014-01-01 03:00:00 77.0
2014-01-01 04:00:00 132.7
2014-01-01 05:00:00 188.1
2014-01-01 06:00:00 141.1
2014-01-01 07:00:00 115.5
I would to wrangle this into a DataFrame that looks like this:
Month 1 2 3 4 5 6 7 8 9 ...
Jan
Feb Data
Mar
...
What is the best way to do this in python pandas? The data in the series is pre formmatted and the index is a datetime. Here is the index:
class 'pandas.tseries.index.DatetimeIndex'
[2014-01-01 00:00:00, ..., 2014-12-31 23:00:00]
Length: 8760, Freq: None, Timezone: None
Upvotes: 1
Views: 454
Reputation: 2263
If I'm understanding correctly it looks like you want to resample your data by summing the hourly values over a monthly time period. You can do that using pandas resample function:
# This will resample your data by month.
df.resample('1M').sum()
Upvotes: 1