持续时间以秒为单位 Pandas

Duration to Seconds in Pandas

怎么能有这样的系列:

2016-11-09 00:07:00    0 days 00:00:15.000000000
2016-11-09 00:07:15    0 days 00:20:14.000000000
2016-11-09 00:07:30    0 days 10:00:15.000000000

像这样的整数值:

2016-11-09 00:07:00    15
2016-11-09 00:07:15    1214 // 20*60+14
2016-11-09 00:07:30    36015 // 10*60*60+15

那些是TimeDeltas. You should be able to use the total_seconds method. However, you'd need to access that method via the datetime accessor dt。假设您的系列名为 s

s.dt.total_seconds()

2016-11-09 00:07:00       15.0
2016-11-09 00:07:15     1214.0
2016-11-09 00:07:30    36015.0
dtype: float64

但是,如果这些是字符串的话。使用 pd.to_timedelta

可能会更好
pd.to_timedelta(s).dt.total_seconds()

2016-11-09 00:07:00       15.0
2016-11-09 00:07:15     1214.0
2016-11-09 00:07:30    36015.0
dtype: float64