我df1
有
Acc_id Acc_name Acc_end_date
qqq-1 test1 12/31/2021
www-2 test2 05/28/2022
yyy-6 test3 06/15/2022
zzz-6 test4 06/17/2022
kkk-6 test5 03/16/2022
Acc_end_date
格式为 mm/dd/yy 。
我试图只获得那些Acc_end_date
- 今天日期> 30的帐户。
意思是,从今天开始应该经过 30 天才Acc_id
能被选中。
我尝试了以下
# changing the column to datetime format
df1['Acc_end_date']= pd.to_datetime(df1['Acc_end_date'])
# getting todays date and creating an array with those number of Acc_id and substracting
todays_date = []
for i in range(df1.shape[0]):
temp = date.today()
todays_date.append(temp)
np.array(todays_date)
df2 = df1[df1['Acc_end_date'] - todays_date>30]
我收到错误消息
TypeError: unsupported operand type(s) for -: 'DatetimeArray' and 'list'
给出错误为
TypeError: unsupported operand type(s) for -: 'DatetimeArray' and 'datetime.date'
试试这个
df2 = df1[only_inactive['Acc_end_date'] - date.today()>30]
我无法获得正确的日期和正确的减法格式。
请帮助任何方法
IIUC,您可以使用:
df2 = df1[pd.to_datetime(df1['Acc_end_date'], dayfirst=False)
.rsub(pd.Timestamp('today')).gt('30d')]
输出:
Acc_id Acc_name Acc_end_date
0 qqq-1 test1 12/31/2021
4 kkk-6 test5 03/16/2022
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句