【发布时间】:2018-12-22 21:08:17
【问题描述】:
尝试使用 panda 在 python 3 中降低和剥离一列,但收到警告 - 正确的方法是什么,因此不会出现此警告
df["col1"] = df[["col1"]].apply(lambda x: x.str.strip())
df["col1"] = df[["col1"]].apply(lambda x: x.str.lower())
警告
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
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
self[k1] = value[k2]
如何消除警告
【问题讨论】:
-
我猜
df_rounds_clean是另一个数据帧的子集? -
您是否阅读了警告链接到的文档章节?问题是这实际上不适用于您的情况,所以您想禁止警告,还是它确实适用,所以您想知道如何解决它,或者您不理解它?
-
您是否按照警告中的说明进行操作?
标签: python python-3.x pandas