Why is chained assignment such as df[df.a > 0]['b'] = 1 unreliable?
-
A
It reorders the index of the frame
-
B
The inner selection may be a copy
Correct answer
-
C
It always raises a KeyError
-
D
It silently converts dtypes to object
Correct answer
B. The inner selection may be a copy
13 views
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
Doubts & discussion
Not sure why the answer is B? Ask here and get an explanation.
Ask a doubt about this MCQ