ValueError:无效的float()文字:28/06/2016

时间:2019-04-16 12:47:41

标签: python jupyter-notebook

我有问题

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

1 个答案:

答案 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是从日期获取时间戳的一些答案。