【问题标题】:How can I count occurrences in a certain column for current time如何计算当前时间某一列中的出现次数
【发布时间】:2019-09-11 05:03:15
【问题描述】:

我的数据框看起来像这样 -

Column 1
Event-Won
Event-Won
Event-lost
Event-Won
Event-lost

我想计算事件的数量(赢/输)并显示某个时间戳(当前时间)的计数。我正在使用这个代码,它给了我计数。但我想将时间戳作为输入,并想查看在该特定时间戳上出现了多少次。

from collections import Counter
countval['newValue'].value_counts()

我想要的输出将是 -

Input- current time (timestamp 1)
Output - Event-won -3 
         Event-lost - 2

Input - future time (timestamp 2)
Output - Event-won - 5
         Event-lost - 3

我将不胜感激任何有关此问题的帮助。

【问题讨论】:

标签: python pandas datetime dataframe data-science


【解决方案1】:

先转换为第二个,然后我们做meanmedian

pd.to_timedelta(pd.to_timedelta(s).dt.total_seconds().median(),unit='s')
Out[927]: Timedelta('39 days 17:54:00')
pd.to_timedelta(pd.to_timedelta(s).dt.total_seconds().mean(),unit='s')
Out[928]: Timedelta('36 days 23:35:10')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-10
    • 2016-01-20
    • 2019-12-13
    • 2017-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多