What caveat applies to df.copy(deep=True) for a column of dtype object holding Python lists?
Correct answer
A. The data and index are copied, but the Python objects inside object columns are not recursively copied, so they remain shared
23 views
A. The data and index are copied, but the Python objects inside object columns are not recursively copied, so they remain shared
23 views
Deep copy semantics: pandas copies the NumPy arrays and the index, but an object array holds references, so mutable Python objects inside remain shared between the two frames. Mutating a list inside a copied frame can therefore affect the original. Genuine independence requires copy.deepcopy or rebuilding the column as new objects.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is A? Ask here and get an explanation.