1

I am trying to add missing values to a column after filtering with a condition using fillna() method. It fills and shows the values but does not update in the dataframe. Tried using the inplace parameter as well. Here is the code I wrote:

csm[csm.Make == "Maruti"]["Odometer (KM)"].fillna(csm[csm.Make == "Maruti"]["Odometer (KM)"].mean(), inplace = True)

Please help me with the solution on how to fix this issue!

1 Answers1

2

You can add DataFrame.loc for change columns in DataFrame, not Series and for avoid chained assignments assign back and remove inplace=True:

m = csm.Make == "Maruti"
csm[m, "Odometer (KM)"] = csm[m, "Odometer (KM)"].fillna(csm[m, "Odometer (KM)"].mean())
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252