Skip to main contentSkip to solution

NameMathsPhysicsChemistryEnglish
Manish40508070
Zainab607050
Richa456575
Rohit90787269
Suman637864
Atul748274
Charu668875

In the DataFrame 'df' given above, which of the following statement will find the total number of NaN in the whole dataset?

Solution

✅ Correct Option: 3

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 0+1+2+2=50 + 1 + 2 + 2 = 5 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().

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question