我有一个时间序列的数据帧,如下所示:
timestamp v IceCreamOrder Location
2018-01-03 02:21:16 Chocolate South
2018-01-03 12:41:12 Vanilla North
2018-01-03 14:32:15 Strawberry North
2018-01-03 15:32:15 Strawberry North
2018-01-04 02:21:16 Strawberry North
2018-01-04 02:21:16 Rasberry North
2018-01-04 12:41:12 Vanilla North
2018-01-05 15:32:15 Chocolate North
我想得到这样的计数:
^{pr2}$由于这是时间序列数据,所以我一直以pandas datetimeindex格式存储时间戳。在
我一开始想知道“草莓”的数量。我最终得到了一个不起作用的代码。在
^{3}$这会导致错误:
TypeError: count() takes 1 positional argument but 2 were given
任何帮助都将不胜感激。在
使用^{} :
^{pr2}$或^{} :
如果您的
timestamp
列有次,只需在使用dt.date
使用这些操作之前删除它们(如果您不想修改列,也许可以创建一个新序列来用于旋转):将^{} (}用于计数
==
)用于比较列string
,而聚集{True
值,因为True
是类似于1
s的进程:如果要计算所有} :
^{pr2}$type
s,请将列IceCreamOrder
添加到groupby
和聚合^{如果所有
datetime
都没有time
s:相关问题 更多 >
编程相关推荐