起初,我不得不用DF與DatetimeIndex索引操作1列:大熊貓拆散不起作用
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
我想繪製的VS一天某一類型的操作次數
所以我按分組行動迄今爲止,使用agg
grouped = dates.groupby([dates.index.to_period(freq = 'D'), 'actiontype']).agg(len)
這給了我multiindexed系列:
...
2014-01-13 action1 435
action2 2067
..
2014-01-14 action1 455
action2 1007
...
這似乎正是我需要的。
但是當使用時unstack
系列擺脫了多指標和繪製我的數據,並得到了錯誤:
In [379]: grouped.unstack()
ValueError: freq not specified and cannot be inferred from first element
什麼,這裏是我的錯誤?謝謝。
我注意到有這個錯誤是一個[未決問題(https://github.com/pydata/pandas/issues/4342)。這與你在這裏看到的有關嗎? – chrisaycock
@chrisaycock我已經看過這個頁面,但我不確定這是否是我的情況。熊貓我很新。 – Timofey