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

Time:03-03

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.

CodePudding user response:

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

train_inf['Age']=train_inf['Age'].fillna(train_inf['Age'].median())
  • Related