kol*_*lja 2 duration timedelta delta pandas
ia系列如何像这样:
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
Run Code Online (Sandbox Code Playgroud)
变成这样的整数值:
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
Run Code Online (Sandbox Code Playgroud)
那些是TimeDeltas
。您应该能够使用该total_seconds
方法。但是,您需要通过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
Run Code Online (Sandbox Code Playgroud)
但是,如果是偶然的话,那是字符串。使用可能会更好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
Run Code Online (Sandbox Code Playgroud)