1. Home
  2. Data Science
  3. Pandas
  4. Why is chained assignment such as df[df.a > 0]['b'] = 1…

Added 30 Nov -0001

Why is chained assignment such as df[df.a > 0]['b'] = 1 unreliable?

  1. It reorders the index of the frame
  2. The inner selection may be a copy Correct answer
  3. It always raises a KeyError
  4. It silently converts dtypes to object

Correct answer

B. The inner selection may be a copy

13 views

MCQSEXAM

Explanation

Chained indexing can target a temporary object, so pandas raises SettingWithCopyWarning and the frame may stay unchanged.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

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