1. Home
  2. Data Science
  3. Pandas
  4. A frame containing NaN values is reshaped with stack() and…

Added 30 Nov -0001

A frame containing NaN values is reshaped with stack() and then unstack(). What is the result compared with the original?

  1. The original shape, with the missing values dropped by the round trip
  2. A transposed frame, because unstack reverses the axes rather than stack
  3. A frame with one extra level, since stack keeps every level intact
  4. The original shape, with the same missing values still in place there Correct answer

Correct answer

D. The original shape, with the same missing values still in place there

13 views

MCQSEXAM

Explanation

stack pivots the innermost column level into the row index and unstack performs the inverse, so a round trip restores the original shape and values. Missing combinations behave differently in each direction: stack has a dropna option while unstack refills absent intersections with NaN. Column order can differ after the round trip even when the values match.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is D? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Pandas MCQs

Practise all Pandas MCQs

Similar MCQs