Missing Values

0/6
Concept[1]

DataFrames often have missing values (NaN). Use `isnull()` to detect them and `.sum()` to count how many exist per column.

python
df.isnull().sum()                    # Count nulls per column
df['age'].isnull().sum()             # Count nulls in one column
Try it[2]

Check how many null values are in the `age` column.

In [ ]:
Quick insert
Concept[3]

Filter out rows with missing values using `notna()` (keeps non-null rows) or `~isnull()` (inverts the null mask). Both give the same result.

python
df_clean = df[df['column'].notna()]       # Keep non-null rows
df_clean = df[~df['column'].isnull()]     # Same thing, inverted mask
Try it[4]

Remove all rows where the `email` column is null.

In [ ]:
Quick insert
Concept[5]

Instead of removing rows, you can fill missing values with `fillna()`. Common strategies: fill with 0, a string like "N/A", or a computed value like the column mean.

python
df.fillna(0)                                  # Fill all nulls with 0
df['price'].fillna(df['price'].mean())        # Fill with column mean
Try it[6]

Fill missing prices with the mean of the `price` column.

In [ ]:
Quick insert