My dataframe consists of multiple columns with NaN values. I want to replace NaN values of only specific column ( column name: MarkDown1) with 0.
The statement I wrote is:
data1.loc[:,['MarkDown1']] = data1.loc[:,['MarkDown1']].fillna(0)
My statement is raising a warning:
C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexing.py:965: 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: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self.obj[item] = s
I request not not to mark my question as duplicate because I have referred the documentation and previous questions and have tried to implement the suggestions given. The suggestion was to use .loc. I have used .loc only in my code as mentioned above. But still I am getting the warning. Kindly suggest the correct syntax to eliminate the warning.