I'm playing with copy.deepcopy from copy package. My intention was to be able to "really" create a copy of a variable in python, as it can be done in R or VBA for instance.
Now take a look at my code:
This is the first part where I load the libraries and download a copy of the iris dataset from the internet.
import copy
import statsmodels.api as sm
dataset_iris = sm.datasets.get_rdataset(dataname='iris',
package='datasets')
Here I'm trying to create a copy by value of the object dataset_iris
iris = copy.deepcopy(dataset_iris)
iris = iris['data']
At this moment if I check the value of first column's name in the original dataset I get two names in uppercase separated by a dot:
print(dataset_iris['data'].columns.values[0])
#Sepal.Length
Than I change the copied dataset's (iris) column first name
iris.columns.values[0] = 'sepal_length'
When I check the original dataset first column's name, it has also changed. This behavior is supposed to be expected if I had done a "copy" with the "=" sign in Python, but not through the usage of package copy and its function deepcopy.
print(dataset_iris['data'].columns.values[0])
#sepal_length
I'm certainly missing something here in basic Python understanding, I just don't know exactly what it is.
Best regards,
Gustavo