I am new to Python, and want to make a copy (x2
) of an existing Pandas dataframe (x1
), and adjust all existing values to another value (or set them to e.g. NaN
). This was attempted as follows:
x1 = pd.DataFrame({'x':[1,2,3], 'y':[4,5,6]})
x2 = x1
x2[:] = 5
x1
After redefining all values of x2
by 5, however, x1
also gets redefined. This behavior of redefinition of existing variables is highly unwanted. Why is this happening and how could it be prevented? Thanks in advance!