1. Home
  2. Data Science
  3. Pandas
  4. How does Series.where(cond, other) differ from…

Added 30 Nov -0001

How does Series.where(cond, other) differ from Series.mask(cond, other)?

  1. where keeps values where the condition holds; mask replaces them there Correct answer
  2. where replaces values where the condition holds; mask keeps them
  3. where drops the rows failing the condition; mask keeps them and fills in
  4. The two are aliases, and only their argument order differs from each other

Correct answer

A. where keeps values where the condition holds; mask replaces them there

14 views

MCQSEXAM

Explanation

where is the keep-mask: entries where the condition is True are retained and everything else is replaced by other, which defaults to NaN. mask is its complement and replaces where the condition is True. Both align on the index labels of the condition, so a condition taken from another frame silently introduces NaN wherever labels fail to match.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is A? 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