What does the df.isnull().sum() function do in Pandas?
What does the df.isnull().sum() function do in Pandas?
Solution
✅ Correct Option: 1
df.isnull() returns a DataFrame of the same shape with True wherever a value is NaN. Calling .sum() on it adds up the True values (counted as 1) down each column, so the result is the count of NaN values in every column (attribute).
Option 3: that describes df.isnull().any(), which only tells whether a column has at least one NaN, not how many.
Options 2 and 4: filling values is done by fillna(), for example df.fillna(df.mean()) or df.fillna(0). isnull() never changes the data.
Related questions:
2025: 15 May Shift 2
2026: 24 May Shift 1
2026: 29 May Shift 2
2026: 29 May Shift 1
2026: 13 May Shift 2