Setup¶
In [1]:
import pandas as pd
import numpy as np
Time Operations¶
In [22]:
long = np.timedelta64(1, 'M')
In [19]:
long2 = pd.to_timedelta(24 * 30, 'D')
long2
Out[19]:
Timedelta('720 days 00:00:00')
In [8]:
pdate = pd.to_datetime('2020-11-3')
pdate
Out[8]:
Timestamp('2020-11-03 00:00:00')
In [9]:
ndate = np.datetime64('2020-11-03')
ndate
Out[9]:
numpy.datetime64('2020-11-03')
In [10]:
ndate + long
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-10-85e807e9154e> in <module> ----> 1 ndate + long TypeError: Cannot get a common metadata divisor for NumPy datetime metadata [D] and [M] because they have incompatible nonlinear base time units
In [23]:
pdate + long
Out[23]:
Timestamp('2020-12-03 10:29:06')
In [25]:
pdate + pd.DateOffset(months=240)
Out[25]:
Timestamp('2040-11-03 00:00:00')
In [24]:
pdate + long2
Out[24]:
Timestamp('2022-10-24 00:00:00')
In [27]:
pdate + pd.DateOffset(months=240) * 2
Out[27]:
Timestamp('2060-11-03 00:00:00')
In [31]:
pd.Series([3, 20, 1]).apply(lambda m: pd.DateOffset(months=m)) + pdate
Out[31]:
0 2021-02-03 1 2022-07-03 2 2020-12-03 dtype: datetime64[ns]
In [ ]: