【问题标题】:Pandas conditional statement datetimePandas 条件语句日期时间
【发布时间】:2022-01-06 18:31:07
【问题描述】:

我已使用此代码成功过滤了我的数据框:

df.set_index('Time')
df.index=pd.to_datetime(df.index)
df.between_time('08:00', '17:00')

现在,df 仅包含指定时间范围内的数据。现在,如果适用此条件,我想计算“位置”列的值。我如何做到这一点?

【问题讨论】:

  • len(df) 没有给你你想要的吗?如果你已经过滤了它,那么你想要行数,对吧?还是有 NaN 可以忽略?
  • 有不同的地点(例如巴黎、柏林),所以我需要计算每个地点。如果我应用 value.counts 它只是在没有条件的情况下计数。

标签: python pandas conditional-statements


【解决方案1】:

试试:

df.between_time('08:00', '17:00')['location'].nunique()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-19
    • 1970-01-01
    • 2015-07-13
    • 1970-01-01
    • 2015-02-09
    • 1970-01-01
    • 2015-03-28
    • 1970-01-01
    相关资源
    最近更新 更多