I'm a new user of python and pandas, and I don't understand how assigning a slice of a pandas df1 to another df2 via the iloc "slicer", copies the data from df1 via reference.
The example code below illustrates my problem. If I use the assignment y = 123, then x stays unchanged. However, if I modify y.iloc[:,:] then by "magic" also x changes. Is y.iloc a pointer to x? if y.iloc is a pointer to x, then why does x stay unchanged if I modify y directly via assignment y = 123?
d = {'col1': [5]}
x = pd.DataFrame(data=d)
print('x equals')
print(x)
y = x.iloc[:,:]
print('y equals')
print(y)
#why does the y.iloc[:,:]=123 also modify x?
y.iloc[0,0] = 123
#y = 123 #this way x is unchanged.
print('y equals')
print(y)
print('x equals')
print(x)