I have a pandas Dataframe with observations of one ID and I have a problem similar to the one solved here.
Timestamp ID
2014-10-16 15:05:17 123
2014-10-16 14:56:37 148
2014-10-16 14:25:16 123
2014-10-16 14:15:32 123
2014-10-16 13:41:01 123
2014-10-16 12:50:30 148
2014-10-16 12:28:54 123
2014-10-16 12:26:56 123
2014-10-16 12:25:12 123
...
2014-10-08 15:52:49 150
2014-10-08 15:04:50 150
2014-10-08 15:03:48 148
2014-10-08 15:02:27 200
2014-10-08 15:01:56 236
2014-10-08 13:27:28 147
2014-10-08 13:01:08 148
2014-10-08 12:52:06 999
2014-10-08 12:43:27 999
Name: summary, Length: 600
On the mentioned post they show how to group by ID and also how to make the count.Using df['Week/Year'] = df['Timestamp'].apply(lambda x: "%d/%d" % (x.week, x.year))
I have now this:
Timestamp ID Week/Year
0 2014-10-16 15:05:17 123 42/2014
1 2014-10-16 14:56:37 150 42/2014
2 2014-10-16 14:25:16 123 42/2014
My problem is that now I want to make a time series so, actually, I need:
Category Week_42_2014 Week_43_2014 Week_44_2014
123 7 0 6
150 0 0 2 ...
This is, I need the weeks as a column, the categories as rows and also fill the gaps of the weeks with no observations. In my case I also need days, but I guess that it is really similar.
Thanks,