我想在数据框中的一列中更新值(有条件)。没有SettingWithCopyWarning怎么办?
我使用.loc函数完成此操作,但是无论如何我都会得到SettingWithCopyWarning
我尝试使用以下代码
df.loc[df.nHeight < 1450, col_name] = df.nHeight + 145
和
df.loc[df['nHeight'] < 1450, 'nHeight'] = df['nHeight'] + 145
在两种情况下(以及其他情况下),我都会收到相同的警告:
lib/python3.6/site-packages/pandas/core/indexing.py:543: SettingWithCopyWarning:
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.obj[item] = s
有什么想法在这种情况下如何删除此警告?