根据时间长度从数据帧中删除timedeltas

时间:2017-06-20 21:56:28

标签: python pandas timedelta

如果timedelta大于16小时,我想从我的数据框中删除行...到目前为止,我没有运气。

数据帧:

    European Central Bank          0 days 20:35:45
    U.S. Federal Reserve           3 days 15:11:52
    U.S. Federal Reserve   84 days 22:19:14.465000
    Central Bank of (..)           0 days 16:20:58
    Bank of Israel                 0 days 11:30:42

我的尝试:

dropped = dropped.drop(dropped[(dropped.diff.dt.hours > 16)].index)

dropped = dropped.drop(dropped[(dropped.diff.hours > 16)].index)

收到错误:

AttributeError: 'function' object has no attribute 'hours'

更新: - 新尝试:

dropped = dropped.drop(dropped[dropped.dt.total_seconds() /(3600)<16])

新错误:

AttributeError: 'DataFrame' object has no attribute 'dt'

1 个答案:

答案 0 :(得分:1)

你可以试试这个:

df[1]=df[1].map(pd.Timedelta)
df[df[1].dt.total_seconds() /(3600)<16]

输出:

             0        1
4  Bank of Israel 11:30:42