我正在尝试根据数据帧中以天为单位的数据寿命执行特定的操作。我正在寻找的东西如下:
import pandas as pd
if 10days < (pd.Timestamp.now() - pd.Timestamp(2019, 3, 20)):
print 'The data is older than 10 days'
是否可以用两个时间戳值之间的差异替换“ 10days”或执行其他操作?
答案 0 :(得分:0)
您要查找的是pd.Timedelta('10D')
,pd.Timedelta(10, unit='D')
(或unit='days'
或unit='day'
)或pd.Timedelta(days=10)
。例如,
In [37]: pd.Timedelta(days=10) < pd.Timestamp.now() - pd.Timestamp(2019, 3, 20)
Out[37]: False
In [38]: pd.Timedelta(days=5) < pd.Timestamp.now() - pd.Timestamp(2019, 3, 20)
Out[38]: True