Initially, I had DF with 1 column of actions indexed using DatetimeIndex:
In [371]: dates
2013-12-29 19:21:00 action1
2013-12-29 19:21:01 action2
2013-12-29 19:21:11 action1
2013-12-29 19:21:13 action2
...
In [372]: dates.index
Out[372]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-12-29 19:02:27, ..., 2014-01-13 16:30:31]
Length: 108957, Freq: None, Timezone: None
I want to build the number of actions of a certain type vs day
So, I grouped the actions by date using agg
grouped = dates.groupby([dates.index.to_period(freq = 'D'), 'actiontype']).agg(len)
What gave me the multi-index series:
...
2014-01-13 action1 435
action2 2067
..
2014-01-14 action1 455
action2 1007
...
This seems to be exactly what I need.
But when you tried the unstackseries to get rid of MultiIndex and build my data and got an error:
In [379]: grouped.unstack()
ValueError: freq not specified and cannot be inferred from first element
What is my mistake here? Thanks.
source
share