I have a times series with temperature and radiation in a pandas dataframe
. The time resolution is 1 minute in regular steps.
import datetime
import pandas as pd
import numpy as np
date_times = pd.date_range(datetime.datetime(2012, 4, 5, 8, 0),
datetime.datetime(2012, 4, 5, 12, 0),
freq='1min')
tamb = np.random.sample(date_times.size) * 10.0
radiation = np.random.sample(date_times.size) * 10.0
frame = pd.DataFrame(data={'tamb': tamb, 'radiation': radiation},
index=date_times)
frame
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 241 entries, 2012-04-05 08:00:00 to 2012-04-05 12:00:00
Freq: T
Data columns:
radiation 241 non-null values
tamb 241 non-null values
dtypes: float64(2)
How can I down-sample this dataframe
to a resolution of one hour, computing the hourly mean for the temperature and the hourly sum for radiation?
frame.resample('1H', how={'radiation': [np.sum, np.min], 'tamb': np.mean})
. The resulting DataFrame has a MultiIndex on its columns, with the original column name as level 0 and the function name as level 1. – Flavoprotein