I am new to Pandas timeseries and dataframes and struggling to complete this simple task. I have data "data" (1-dimensional array float32-Numpy) for each day from 01/01/2004 to 12/31/2008. Dates are stored as a list of date and time date objects. In principle, I would like to calculate the full "standard year" - the average value of each day of all years (1-365). I started with this similar (?) Question ( Getting the average value of a specific hour on weekdays for several years in the Pandas data framework ), but I couldnโt get to the desired result - a time series of 365 โaverageโ days, for example, for all four January 1, January 2 ...
A small example script:
import numpy as np import pandas as pd import datetime startdate = datetime.datetime(2004, 1, 1) enddate = datetime.datetime(2008, 1, 1) days = (enddate + datetime.timedelta(days=1) - startdate).days data = np.random.random(days) dates = [startdate + datetime.timedelta(days=x) for x in range(0, days)] ts = pd.Series(data, dates) test = ts.groupby(lambda x: (x.year, x.day)).mean()
source share