Reputation: 193
I would like to convert a column of float value to string, following is my current way:
userdf['phone_num'] = userdf['phone_num'].apply(lambda x: "{:.0f}".format(x) if x is not None else x)
However, it also converts the NaN to string "nan" which is bad when I check the missing value in this column, any better idea?
Thanks!
Upvotes: 6
Views: 8369
Reputation: 9931
I think you should compare Nan values instead of comparing None
userdf['phone_num'] = userdf['phone_num'].apply(lambda x: "{:.0f}".
format(x) if not pd.isnull(x) else x)
Upvotes: 3