data = np.random.randn(5,4)
df = pd.DataFrame(data,columns=list('ABCD'),index=[1,2,'a','b','2006-10-1'])
#尝试复制一份df的副本并命名为df_1
df_1 = df
#对副本df_1进行修改
df_1['Else'] = df_1['A']
#发现原数据帧df也被修改了
df.info()
输出情况:
<class 'pandas.core.frame.DataFrame'>
Index: 5 entries, 1 to 2006-10-1
Data columns (total 5 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 A 5 non-null float64
1 B 5 non-null float64
2 C 5 non-null float64
3 D 5 non-null float64
4 Else 5 non-null float64
dtypes: float64(5)
memory usage: 240.0+ bytes
请问如何才能保存一个新的数据帧副本,以防止原数据被修改?