0

Please help me understand why this syntax is not working

data[data.country == 'SA'].postal_code.fillna(data[data.country == 'SA'].postal_code.mode(), inplace=True)

Basically what I want to do is fillna() the postal_code column with the most frequent postal code where the country is equivalent to SA. When I run the above code I don't get an error, however when I run data[data.postal_code.isnull()] I still get NaN's in the postal code column where country == 'SA'

Mengezi Dhlomo
  • 335
  • 1
  • 3
  • 13
  • Because the inplace operation was done on a sliced copy. Try `data.update(data[data.country == 'SA'].postal_code.fillna(data[data.country == 'SA'].postal_code.mode())`? – Chris Feb 06 '20 at 08:55
  • Still doesn't work. Also doesn't return an error but the postal code column still has `NaN`'s in it – Mengezi Dhlomo Feb 06 '20 at 09:07

0 Answers0