Is it possible to create a dataframe where one fragment is a view of another df and the remaining fragment is not a view?
I am unable to create such a df, but I want to know if it is possible.
If this is possible, can you give an example of such a dataframe?
>Solution :
I think you can make something like this when you construct the dataframe with copy=False parameter. Consider this:
arr = np.array([[1, 2, 3], [4, 5, 6]])
df1 = pd.DataFrame(arr, columns=["a1", "b1", "c1"], copy=False)
df2 = pd.DataFrame(arr, columns=["a2", "b2", "c2"], copy=False)
df2["d"] = 999
print(df1)
print(df2)
This prints:
a1 b1 c1
0 1 2 3
1 4 5 6
a2 b2 c2 d
0 1 2 3 999
1 4 5 6 999
Now when you do:
df1.loc[0, :] = -1
print(df1)
print(df2)
This prints:
a1 b1 c1
0 -1 -1 -1
1 4 5 6
a2 b2 c2 d
0 -1 -1 -1 999
1 4 5 6 999