Skip to content
Advertisement

Try to replace the nan values by pandas , but Error: Columns must be same length as key

It is a simple project in Kaggle, just imitating one blog, but failed. enter image description here

train_inf[‘Age’]=train_inf.fillna(train_inf[‘Age’].median()) ValueError: Columns must be same length as key

just this code

I am searching for a long time on net. But no use. Please help or try to give some ideas how achieve this. Thanks in advance.

Advertisement

Answer

You are close, need specify column Age for replace missing values:

train_inf['Age']=train_inf['Age'].fillna(train_inf['Age'].median())
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement