参考地址:https://pandas.pydata.org/pandas-docs/stable/reference/offset_frequency.html
第四课 Pandas时序型数据分析
第三节 时序型数据运算
import pandas as pd
Timedelta
pd.Timedelta('1 day')
Timedelta('1 days 00:00:00')
pd.Timedelta('1 day 2 hours')
Timedelta('1 days 02:00:00')
pd.to_timedelta(['1 day', '1 day 2 hours'])
TimedeltaIndex(['1 days 00:00:00', '1 days 02:00:00'], dtype='timedelta64[ns]', freq=None)
运算
s = pd.Series(pd.date_range('2019-1-1', periods=10, freq='D'))
td = pd.Series([pd.Timedelta(days=i) for i in range(10)])
df = pd.DataFrame({
'A': s, 'B': td})
df
A B
0 2019-01-01 0 days
1 2019-01-02 1 days
2 2019-01-03 2 days
3 2019-01-04 3 days
4 2019-01-