April 20, 2020

Dealing with Missing Values

  1. Missing elements usually show up as NaN (Not a Number)

  2. Method #1 - Drop all the rows with a missing value

    1. We can use .dropna( )

      1. bill_df = bill_df.dropna()

    2. If we only want to drop rows with NaN in a single column, we can drop a subset

      1. bill_df - bill_df.dropna(subset = [‘num_guests’])

  3. Method #2 - Fill the missing values with the mean of the column, or some other aggregate value.

    1. We can use .fillna( )

      1. bill_df = bill_df.fillna(value = {“bill” : bill_df.bill.mean(), “num_guests” : bill_df.num_guests.mean()})

Previous
Previous

April 26, 2020

Next
Next

April 19, 2020