I just discovered the power of Pandas, and I like it, but I can not understand this problem:
I have a DataFrame df.head() :
lon lat h filename time 0 19.961216 80.617627 -0.077165 60048 2002-05-15 12:59:31.717467 1 19.923916 80.614847 -0.018689 60048 2002-05-15 12:59:31.831467 2 19.849396 80.609257 -0.089205 60048 2002-05-15 12:59:32.059467 3 19.830776 80.607857 0.076485 60048 2002-05-15 12:59:32.116467 4 19.570708 80.588183 0.162943 60048 2002-05-15 12:59:32.888467
I would like to group my data into nine time intervals
gb = df.groupby(pd.TimeGrouper(key='time', freq='9D'))
First group:
2002-05-15 12:59:31.717467 lon lat h filename time 0 19.961216 80.617627 -0.077165 60048 2002-05-15 12:59:31.717467 1 19.923916 80.614847 -0.018689 60048 2002-05-15 12:59:31.831467 2 19.849396 80.609257 -0.089205 60048 2002-05-15 12:59:32.059467 3 19.830776 80.607857 0.076485 60048 2002-05-15 12:59:32.116467 ...
Next group:
2002-05-24 12:59:31.717467 lon lat height filename time 815 18.309498 80.457024 0.187387 60309 2002-05-24 16:35:39.553563 816 18.291458 80.458514 0.061446 60309 2002-05-24 16:35:39.610563 817 18.273408 80.460014 0.129255 60309 2002-05-24 16:35:39.667563 818 18.255358 80.461504 0.046761 60309 2002-05-24 16:35:39.724563 ...
Thus, the data are grouped for nine days, counting from the first time (12: 59: 31.717467), and not from the very beginning of the day, as we would like.
When grouping for one day:
gb = df.groupby(pd.TimeGrouper(key='time', freq='D'))
gives me:
2002-05-15 00:00:00 lon lat h filename time 0 19.961216 80.617627 -0.077165 60048 2002-05-15 12:59:31.717467 1 19.923916 80.614847 -0.018689 60048 2002-05-15 12:59:31.831467 2 19.849396 80.609257 -0.089205 60048 2002-05-15 12:59:32.059467 3 19.830776 80.607857 0.076485 60048 2002-05-15 12:59:32.116467 ...
I can just go in cycles the other day until I get a nine-day interval, but I think it can be done smarter, I'm looking for a Grouper freq option equivalent to YS (beginning of the year) in just a few days, a way to set the start time (perhaps using the option Grouper convention : {'start', 'end', 'e', 's'} ) or
I am running Python 3.5.2 and Pandas is in version: 0.19.0