日期之间的天数(如果有)

2024-10-06 11:17:34 发布

您现在位置:Python中文网/ 问答频道 /正文

试图在数据框中添加列,如果两个单独列中的日期间隔超过一定数量,则返回值。你知道吗

if (cust_ledger['Posting Date_x'].shift(14, freq=pd.datetools.Day)) < datime.now():

我在上面一行得到了以下错误

NotImplementedError: Not supported for type Int64Index

Tags: 数据数量date间隔ifshiftpdfreq
1条回答
网友
1楼 · 发布于 2024-10-06 11:17:34

怎么样:

import pandas as pd cust_ledger['newCol'] = cust_ledger['dataSource'][cust_ledger['date1']-cust_ledger['date2'] > pd.Timedelta(14)]

此代码将为“date1”-“date2”>;14天的行创建一个新列“newCol”,其中包含“dataSource”列中的数据。对于不满足此条件的行,可能将包含NaN。应该可以用datetime.now()交换客户分类账['date2']

相关问题 更多 >