I have some hierarchical data from 2003 to 2011 which bottoms out into time series data which looks something like this:
polar_temp
Station_Number Date Value
417 CA002100805 20030101 -296
423 CA002202570 20030101 -269
425 CA002203058 20030101 -268
427 CA002300551 20030101 -23
428 CA002300902 20030101 -200
I set a multi index on Station_Number and Date:
polar_temp['Date'] = pd.to_datetime(polar_temp['Date'],
format='%Y%m%d')#.dt.strftime("%Y-%m-%d")
polar_temp = polar_temp.set_index(['Station_Number', "Date"])
Value
Station_Number Date
CA002100805 2003-01-01 -296
CA002202570 2003-01-01 -269
CA002203058 2003-01-01 -268
CA002300551 2003-01-01 -23
CA002300902 2003-01-01 -200
Now I would like to perform a resampling of the data by calculating the mean of Value for every 8 days by using:
polar_temp8d = polar_temp.groupby([pd.Grouper(level='Station_Number'),
pd.Grouper(level='Date', freq='8D')]).mean()
Value
Station_Number Date
CA002100805 2003-01-01 -300.285714
2003-01-09 -328.750000
2003-01-17 -325.500000
2003-01-25 -385.833333
2003-02-02 -194.428571
... ...
USW00027515 2005-06-23 76.625000
2005-07-01 42.375000
2005-07-09 94.500000
2005-07-17 66.500000
2005-07-25 56.285714
So the problem here is that pandas only resamples the years from 2003 until 2005, so the years from 2006 to 2011 are completely left out. Now my question is: Did I use the Grouper function to analyse time series data correctly or is the anything else I have missed?
Edit 1:
By running:
print(polar_temp.loc['CA002300902'].sort_index(ascending=False))
Value
Date
2011-12-31 -288
2011-12-30 -299
2011-12-29 -347
2011-12-28 -310
2011-12-27 -239
One can see that the stations before the resampling have data until 2011.