Could you please let me know why the new column c
is added to the original dataframe i.e., df_old
?
df_old = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})
df_new=df_old
df_new['c']=[5,6]
print('Old:')
print(df_old)
print('New:')
print(df_new)
Output:
Old:
a b c
0 1 3 5
1 2 4 6
New:
a b c
0 1 3 5
1 2 4 6
In fact, I need to preserve the original dataframe as it was:
a b
0 1 3
1 2 4
Thanks in advance,