How to resample a dataframe with different functions applied to each column?

With pandas 0.18 the resample API changed (see the docs). So for pandas >= 0.18 the answer is: In [31]: frame.resample(‘1H’).agg({‘radiation’: np.sum, ‘tamb’: np.mean}) Out[31]: tamb radiation 2012-04-05 08:00:00 5.161235 279.507182 2012-04-05 09:00:00 4.968145 290.941073 2012-04-05 10:00:00 4.478531 317.678285 2012-04-05 11:00:00 4.706206 335.258633 2012-04-05 12:00:00 2.457873 8.655838 Old Answer: I am answering my question to … Read more

Annotate Time Series plot

Matplotlib uses an internal floating point format for dates. You just need to convert your date to that format (using matplotlib.dates.date2num or matplotlib.dates.datestr2num) and then use annotate as usual. As a somewhat excessively fancy example: import datetime as dt import matplotlib.pyplot as plt import matplotlib.dates as mdates x = [dt.datetime(2009, 05, 01), dt.datetime(2010, 06, 01), … Read more

Time Series Decomposition function in Python

I’ve been having a similar issue and am trying to find the best path forward. Try moving your data into a Pandas DataFrame and then call StatsModels tsa.seasonal_decompose. See the following example: import statsmodels.api as sm dta = sm.datasets.co2.load_pandas().data # deal with missing values. see issue dta.co2.interpolate(inplace=True) res = sm.tsa.seasonal_decompose(dta.co2) resplot = res.plot() You can … Read more

Pandas Resampling error: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex

Convert the integer timestamps in the index to a DatetimeIndex: data.index = pd.to_datetime(data.index, unit=”s”) This interprets the integers as seconds since the Epoch. For example, given data = pd.DataFrame( {‘Timestamp’:[1313331280, 1313334917, 1313334917, 1313340309, 1313340309], ‘Price’: [10.4]*3 + [10.5]*2, ‘Volume’: [0.779, 0.101, 0.316, 0.150, 1.8]}) data = data.set_index([‘Timestamp’]) # Price Volume # Timestamp # 1313331280 10.4 … Read more