根据时间长度从数据帧中删除时间增量
Dropping timedeltas from dataframe based on length of time
如果 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'
你可以试试这个:
df[1]=df[1].map(pd.Timedelta)
df[df[1].dt.total_seconds() /(3600)<16]
输出:
0 1
4 Bank of Israel 11:30:42
如果 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'
你可以试试这个:
df[1]=df[1].map(pd.Timedelta)
df[df[1].dt.total_seconds() /(3600)<16]
输出:
0 1
4 Bank of Israel 11:30:42