2024-10-06 11:17:34 发布
网友
试图在数据框中添加列,如果两个单独列中的日期间隔超过一定数量,则返回值。你知道吗
if (cust_ledger['Posting Date_x'].shift(14, freq=pd.datetools.Day)) < datime.now():
我在上面一行得到了以下错误
NotImplementedError: Not supported for type Int64Index
怎么样:
import pandas as pd cust_ledger['newCol'] = cust_ledger['dataSource'][cust_ledger['date1']-cust_ledger['date2'] > pd.Timedelta(14)]
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']
datetime.now()
怎么样:
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']相关问题 更多 >
编程相关推荐