0

I have a dataframe that has about 15 numeric columns, and for some reason when I pass those numeric columns as a list into the pd.fillna() method, 3 of them don't have their values filled, and I'm not sure why this is the case.

MY CODE:

num_cols = df.select_dtypes(include=[np.number]).columns.tolist()

num_cols then looks like this:

numeric columns

Then I pass num_cols into the dataframe using the fillna method, but some of the columns aren't affected by it.

df[num_cols].fillna(df[num_cols].median(), inplace=True)
df[num_cols].isnull().sum()

This last command produces the following picture:

Sum of empty values for numeric columns

Any idea why this wouldn't be working?

Jonathan Bechtel
  • 3,497
  • 4
  • 43
  • 73

0 Answers0