Manipulating Data Part 3
Missing Values & NaN
If the data we have imported contains missing values, Pandas will go ahead and enter “NaN” into the cell for you. It’s up to you what you want to do with that “NaN”. Here is how to fill (replace) that data:
Use the function “fillna()” to fill in NaN values:
Dataframe.fillna(self, value = none, method = none, axis = none, inplace = false, limit = none, downcast = none)
I modified this for my scenario:
car_sales_missing[“Odometer”] = car_sales_missing[“Odometer”].fillna(car_sales_missing[“Odometer”].mean(),inplace=True)
- Note on using inplace: boolean, default false — if true, fill in-place (this is the instruction to write over the NaN value).
The result is the NaN values are overwritten with data.