Skip to main contentSkip to solution

Considering s1 = pd.Series([2,3,np.nan,7, np.nan,9,11])

What will be the output of the following statement?

s1.dropna().tail(4)

Solution

✅ Correct Option: 2

dropna() removes the NaN values and returns [2,3,7,9,11][2, 3, 7, 9, 11], with the original index labels 0, 1, 3, 5, 6 kept. tail(4) then returns the last 4 of these values: 3, 7, 9, 11, with index labels 1, 3, 5, 6.


Option 1: this ignores dropna(), which removes every NaN.

Option 4: this is what head(4) would give, not tail(4).

Pandas stores these values as floats because the original Series contains NaN, so the printed values appear as 3.0, 7.0, 9.0, 11.0.

Keyboard Shortcuts

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