Python出现警告:A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead.
df["a"] = target["a"].str.strip().copy()
试了copy(),还是会出现报错。是什么原因呢?谢谢!
Python出现警告:A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead.
df["a"] = target["a"].str.strip().copy()
试了copy(),还是会出现报错。是什么原因呢?谢谢!
在python中默认的切片数据类型是“只读不能写”的,就比如生物实验中的切片,仅供观赏,而使用loc函数定位到的是原dataframe中的列,所以可修改。
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
只不过是个warning,不影响程序跑 ;p