糖逗 发表于 2020-6-25 10:09:38

python学习【深拷贝】【浅拷贝】【DateFrame.copy(deep=True) 】

本帖最后由 糖逗 于 2021-7-31 14:46 编辑

深拷贝和浅拷贝的区别:
当deep=True时(默认), 会创建一个新的对象进行拷贝. 修改这份拷贝不会对原有对象产生影响.

当deep=False时, 新的对象只是原有对象的references. 任何对新对象的改变都会影响到原有对象



案例代码:
In : s = pd.Series([,])                        

In : s                                                      
Out:
0   
1   
dtype: object

In : deep = s.copy()                                       

In : s = 10                                          

In : s                                                      
Out:
0   
1   
dtype: object

In : deep                                                   
Out:
0   
1   
dtype: object



内容转载:https://blog.csdn.net/lancegentry/article/details/99824524


页: [1]
查看完整版本: python学习【深拷贝】【浅拷贝】【DateFrame.copy(deep=True) 】