In [1]:
import pandas as pd
import numpy as np
In [2]:
pd.Timedelta('-3 days'), pd.Timedelta('13 min'), pd.Timedelta(1, unit='M')
Out[2]:
In [3]:
pd.to_timedelta('2 days'), pd.to_timedelta(np.arange(10), unit='M')
Out[3]:
In [4]:
df = pd.DataFrame(dict(A = pd.Series(pd.date_range('2014/1/1/', periods=3)), B = [pd.Timedelta(days=i + 1) for i in range(3)]))
df['C'] = df['A'] + df['B']
df['D'] = df['C'] - max(df['B'])
df['E'] = df['D'] + pd.tseries.offsets.Day(10)
df
Out[4]:
In [5]:
df['B'].mean()
Out[5]:
In [6]:
df['B'].sum()
Out[6]:
In [7]:
s = pd.Series([pd.Timedelta(days=np.random.randint(10)) for i in range(5)])
s
Out[7]:
In [8]:
s / np.timedelta64(1, 'D')
Out[8]:
In [9]:
s.astype('timedelta64[D]')
Out[9]:
In [10]:
s.dt.days
Out[10]:
In [11]:
s.dt.components
Out[11]:
In [12]:
pd.TimedeltaIndex(['1 days', '1 days 00:00:03', np.timedelta64(2, 'M')])
Out[12]:
In [13]:
pd.timedelta_range(start='1 hours', freq='5H', periods=10)
Out[13]:
In [14]:
s = pd.Series(np.arange(100), index=pd.timedelta_range('1 days', periods=100, freq='H'))
s['1 days': '2 days']
Out[14]:
In [15]:
s['1 days 23 hours']
Out[15]:
In [16]:
s[pd.Timedelta('3 days 2 hours')]
Out[16]:
In [17]:
s.resample('D', how='sum')
Out[17]: