My pandas dataframe datainput
has 4 columns namely COLUMN1
, COLUMN2
,COLUMN3
, COLUMN4
each with values of Yes
or No
.
I am trying to replace "Yes" and "No" values in a pandas dataframe with 1 and 2 using the following code
datainput.COLUMN1.replace(("Yes","No"),(1,0),inplace=True)
datainput.COLUMN2.replace(("Yes","No"),(1,0),inplace=True)
datainput.COLUMN3.replace(("Yes","No"),(1,0),inplace=True)
datainput.COLUMN4.replace(("Yes","No"),(1,0),inplace=True)
I am getting it successfully converted but I am getting an associated warning.
C:\Users\mmpra\Anaconda3\lib\site-packages\pandas\core\generic.py:6786: 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/user_guide/indexing.html#returning-a-view-versus-a-copy
self._update_inplace(new_data)
How to avoid the warning and what does it mean?