Reputation: 23
I am doing a project as a python and machine learning beginner and came across Titanic dataset. I wanted to fill the NaN (fillna) value with mean for continuous data. But when I did this:
df['Age']=df['Age'].fillna(df['Age'].mean())
df['Age'].isnull().sum()
It always gives me
TypeError: can only concatenate str (not "int") to str.
Both data types are object and I have tried to change the data type but it is useless. How can I solve this?
Upvotes: 2
Views: 1906
Reputation: 1950
You have to convert your column to int type, using to_numeric()
.
df["Age"] = pd.to_numeric(df["Age"])
Upvotes: 2