Why is it not possible to pass attributes of an instance through a copy? I want to pass the name
attribute to another dataframe.
import copy
df = pd
This code is worked:
>>> class test():
... @property
... def name(self):
... return self._name
... @name.setter
... def name(self, value):
... self._name = value
...
>>>
>>> a = test()
>>> a.name = 'Test123'
>>> import copy
>>> a2 = copy.deepcopy(a)
>>> print(a2.name)
Test123
so I think that behavior is defined by pd.DataFrame
I found that pandas define the function __deepcopy__
, but I cannot totally understand the reason.
pandas/core/indexes/base.py#L960