I have a pd.Series
with each cell being a list.
I want to make a deep copy of it, however it seems like pd.Series.copy
only creates a shallow copy of the values (even though the deep
arg is True
be default).
example
import pandas as pd
sr = pd.Series([list(range(3)), list(range(3))])
sr_c = sr.copy()
sr[0].append(4)
the copied pd.Series
sr_c
is being transformed to
0 [0, 1, 2, 4]
1 [0, 1, 2]
I did this and it worked:
from copy import deepcopy
sr_c = sr_c.apply(deepcopy)
however this seems like a hack, is there a better way to do it ?