我有一个dataframe a=pd.DataFrame({"A":[1,2,3,4,5,6]})
怎样复制得到另一个一模一样的dataframe b?
dataframe.copy()中deep是True和False有什么区别?
import pandas as pd
a=pd.DataFrame({"A":[1,2,3,4,5,6]})
b=a.copy()
print("a",id(a),a.columns)
print("b",id(b),b.columns)
b.columns=["B"]
print("a",id(a),a.columns)
print("b",id(b),b.columns)
结果为:
a 35432320 Index(['A'], dtype='object')
b 99956440 Index(['A'], dtype='object')
a 35432320 Index(['A'], dtype='object')
b 99956440 Index(['B'], dtype='object')
是不是这样就生成了一个新的对象b与a的内容一模一样?
用copy.deepcopy吧。