Reputation: 924
I would like to drop rows from my dataframe if the timedelta is greater than 16 hours...so far I have had no luck.
Dataframe:
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
My attempts:
dropped = dropped.drop(dropped[(dropped.diff.dt.hours > 16)].index)
dropped = dropped.drop(dropped[(dropped.diff.hours > 16)].index)
Error received:
AttributeError: 'function' object has no attribute 'hours'
Update: -new attempt:
dropped = dropped.drop(dropped[dropped.dt.total_seconds() /(3600)<16])
New error:
AttributeError: 'DataFrame' object has no attribute 'dt'
Upvotes: 0
Views: 107
Reputation: 153460
You can try this:
df[1]=df[1].map(pd.Timedelta)
df[df[1].dt.total_seconds() /(3600)<16]
Output:
0 1
4 Bank of Israel 11:30:42
Upvotes: 1