I am doing a binary classification problem (
1). My dataset contains some NaN values in 6-7 columns.
I want to fill those NaN with
most_frequent() of each column. But it should be filled with two different values depending on the target.
NaN for all those with
mode() of values with
Target=1 should be filled and similarly, for all those with
mode() for of values with
I've tried the following code:
Both of these codes didn't worked. I was still left with the same amount of
But, when I run this- train_df[train_df.TARGET==0].fillna(train_df[train_df.TARGET==0].mode()).isnull().sum()
I observed all the missing values do get filled where
Sometimes, I get this Warning:
/opt/conda/lib/python3.6/site-packages/pandas/core/generic.py:6287: 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)
I'm stuck at this for a long time and don't know how to proceed. Please suggest some solution to this.