I have assigned a variable aae with one column of pandas dataframe. If any modification is made on variable aae then the values of pandas dataframe get automatically modified. Please look at this example:

modification in aae makes an automatic change in pandas dataframe value without any direct change made in df['Absorption_Angstrom_Exponent_440-870nm']. If aae is modified then pandas dataframe df should not be changed. Please help me with this automatic update issue with pandas dataframe.
CodePudding user response:
Don't use .values but to_numpy(copy=True):
a = df.to_numpy(copy=True)
Example:
df = pd.DataFrame(np.zeros((3, 3), dtype=int))
a = df.to_numpy(copy=True)
a[0, 0] = 999
output:
0 1 2
0 0 0 0
1 0 0 0
2 0 0 0
Same thing with .values:
0 1 2
0 999 0 0
1 0 0 0
2 0 0 0
