我有问题
for i in range(len(member_KPIs)) :
member_id = member_KPIs.loc[i,"ID_SAFAR"]
#member_activity['ACTIVITY_DATE'] = pd.to_numeric(member_activity['ACTIVITY_DATE'])
#print(member_id)
member_id_filter = member_activity["MEMBER_ID"] == member_id
filtered_members_activity = member_activity[member_id_filter]
max_activity_date = max(filtered_members_activity["ACTIVITY_DATE"])
member_KPIs.at[i,'LAST_TRAVEL_DATE'] = max_activity_date
答案 0 :(得分:0)
我认为您在此行上有错误:
max_activity_date = max(filtered_members_activity["ACTIVITY_DATE"])
似乎您正在尝试将字符串列表提供给max()函数,该函数不起作用; max()需要数字(即浮点数),而不是日期字符串。如果您需要比较这些日期,可以尝试将它们转换为时间戳:
import time, datetime #required for timestamp conversion
#quick and dirty list comprehension
max_activity_date = max([time.mktime(datetime.datetime.strptime(s, "%d/%m/%Y").timetuple()) for s in filtered_members_activity["ACTIVITY_DATE"])
Here是从日期获取时间戳的一些答案。