>>>> data_frame
flog \
first
0037B4F499705D725C2B3B00956B574E NaT
009A27C31C21B5C47ADD76F1C0158864 NaT
016E73F1038CE46AF4A619453AC7DE70 2014-06-03 05:03:38.869000
0250F3B15665E8B00F7D58CCA8C2C8F4 2014-06-03 05:04:38.869000
0260FA375596B150DF8B4D7E3CA2D934 2014-06-03 05:04:44.015000
我需要按分钟进行分组。
例如,应该可以说2014-06-03 05:04
:2
,2014-06-03 05:03
:1
我怎么能在熊猫中做到这一点?
更新: DATA实际上是这样的:
>>>> data_frame
flog \ glog \
first first
0037B4F499705D725C2B3B00956B574E NaT 2014-06-03 05:03:38.869000
009A27C31C21B5C47ADD76F1C0158864 NaT 2014-06-03 05:04:38.869000
016E73F1038CE46AF4A619453AC7DE70 2014-06-03 05:03:38.869000 2014-06-03 05:05:38.869000
0250F3B15665E8B00F7D58CCA8C2C8F4 2014-06-03 05:04:38.869000 NaT
0260FA375596B150DF8B4D7E3CA2D934 2014-06-03 05:04:44.015000 naT
我该如何显示:
TIME flog glog
first first
2014-06-03 05:03: 1 1
2014-06-03 05:04: 2 1
2014-06-03 05:05: 0 1
答案 0 :(得分:1)
只需resample
。请注意,NaT
目前是一个错误(在0.14.0中),因此您需要先删除它们。
In [18]: df.dropna().set_index('date').resample('1T',how='count')
Out[18]:
value
date
2014-06-03 05:03:00 1
2014-06-03 05:04:00 2