首页 > 解决方案 > df.loc[df.loc[:,'Col1'].str.contains('_id'),'Col2']='stringValue'

问题描述

我对适用于我的数据框有一个布尔掩码:

df.loc[df.loc[:,'Col1'].str.contains('_id'),'Col2']='stringValue'

但得到错误

/opt/conda/lib/python3.6/site-packages/pandas/core/indexing.py:141: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  self._setitem_with_indexer(indexer, value)
/opt/conda/lib/python3.6/site-packages/ipykernel_launcher.py:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  """Entry point for launching an IPython kernel.

我已经对此进行了研究,并且无法想出一种方法来编写它而不会得到此错误的任何帮助?

标签: pythonpandas

解决方案


推荐阅读