你可以转换
timedelta
秒到秒
total_seconds
与标量相比:
df = df[df['col'].dt.total_seconds() < 30]
或与
Timedelta
:
df = df[df['col'] < pd.Timedelta(30, unit='s')]
样品
:
df = pd.DataFrame({'col':pd.to_timedelta(['25:10:01','00:01:20','00:00:20'])})
print (df)
col
0 1 days 01:10:01
1 0 days 00:01:20
2 0 days 00:00:20
df = df[df['col'].dt.total_seconds() < 30]
print (df)
col
2 00:00:20