Reputation: 79
I am getting a type when splitting a column of my dataframe, but I can't seem to cast the column as string type to fix it. The series is currently an object-type.
for idx, row in enumerate(df.top_5_investors):
for item in row.split(", "):
df3.loc[idx, item] = 1
AttributeError: 'float' object has no attribute 'split'
I've tried a number of different approaches and found answers on this site that, but data type is still object:
df.astype(str)['top_5_investors'].map(lambda x: type(x))
df.top_5_investors.fillna('')
The desired result would turn the entire column 'top_5_investors' into string-type.
Upvotes: 0
Views: 30
Reputation: 821
In the astype
documentation of pandas, you can use it to convert your df.top_5_investors
to a string columns
df['top_5_investors'] = df.top_5_investors.astype(str)
Upvotes: 1