Currently I have a dataset with a column that has number of unwanted value 'NOT SPECIFIED'
df.groupby('Type')['Type'].value_counts()
| Type | Count |
|---|---|
| Emergency | 1932 |
| NOT SPECIFIED | 391 |
| OPD | 1631 |
| Inpatient | 424 |
I need to change 'NOT SPECIFIED' randomly to one of the other three values, so I wrote this code
vals = ['Emergency', 'Inpatient', 'OPD']
df[df.Type =='NOT SPECIFIED']['Type'] = np.random.choice(vals, len(df[df.Type == 'NOT SPECIFIED']))
and
df.loc[df.Type =='NOT SPECIFIED',:]['Type'] = np.random.choice(vals, len(df[df.Type == 'NOT SPECIFIED']))
But I got this error in both cases
'<'ipython-input-38-6c55b8087eb1'>':2: 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