简体   繁体   中英

Pandas dataframe split() 'float' object has no attribute 'split'

I have a date columns like 2016-12-15 . df["first_review"].dt does not work (it says the column type is not datetime).

I am trying to separate manually but I have error:

AttributeError: 'float' object has no attribute 'split'. 

What can I do? The missing value representation is that 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"])

The solution is that

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("-")

The missing value type is float. The problem is based on that

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM