我有一个像2016-12-15这样的日期列。df["first_review"].dt不起作用(它显示列类型不是datetime)。
我正在尝试手动分离,但出现错误:
AttributeError: 'float' object has no attribute 'split'. 我能做什么?缺少的值表示是NaN。
dates = ["first_review","host_since","last_review"]
for i in dates:
for j in range(len(df)):
df[i+"_year"],df[i+"_month"],df[i+"_day"] = df.loc[j,i].split("-")
display_all(df["first_review_year"])发布于 2020-08-28 20:41:42
解决方案是
df[i+"_year"],df[i+"_month"],df[i+"_day"] = (0,0,0) if type(df.loc[j,i]) == float else df.loc[j,i].split("-")缺少的值类型为float。这个问题就是基于这一点。
https://stackoverflow.com/questions/63633646
复制相似问题