April 20, 2020
Dealing with Missing Values
Missing elements usually show up as NaN (Not a Number)
Method #1 - Drop all the rows with a missing value
We can use .dropna( )
bill_df = bill_df.dropna()
If we only want to drop rows with NaN in a single column, we can drop a subset
bill_df - bill_df.dropna(subset = [‘num_guests’])
Method #2 - Fill the missing values with the mean of the column, or some other aggregate value.
We can use .fillna( )
bill_df = bill_df.fillna(value = {“bill” : bill_df.bill.mean(), “num_guests” : bill_df.num_guests.mean()})