Name Maths Physics Chemistry English Manish 40 50 80 70 Zainab 60 70 50 Richa 45 65 75 Rohit 90 78 72 69 Suman 63 78 64 Atul 74 82 74 Charu 66 88 75
In the DataFrame 'df' given above, which of the following statement will find the total number of NaN in the whole dataset?
| Name | Maths | Physics | Chemistry | English |
|---|---|---|---|---|
| Manish | 40 | 50 | 80 | 70 |
| Zainab | 60 | 70 | 50 | |
| Richa | 45 | 65 | 75 | |
| Rohit | 90 | 78 | 72 | 69 |
| Suman | 63 | 78 | 64 | |
| Atul | 74 | 82 | 74 | |
| Charu | 66 | 88 | 75 |
In the DataFrame 'df' given above, which of the following statement will find the total number of NaN in the whole dataset?
Solution
df.isnull() returns a True/False table of the same shape as df, with True where a value is NaN. The first sum counts the True values in each column, giving a count per column. A second sum then adds those column counts into one total. Here the column counts are NaN values in the whole dataset.
As printed, Option 3 omits the brackets after the first sum. The intended code is df.isnull().sum().sum().
Option 1: counts NaN separately for each column and does not give one total.
Options 2 and 4: pandas has no isNaN() method. The valid methods are isnull() and isna().
Related questions:
2025: 13 May Shift 2
2026: 23 May Shift 1
2026: 23 May Shift 1
2025: 30 May Shift 2