I have a column in a pandas data frame, among other columns, as such:
Remarks
Left_only
Right_only
Left_only
Right_only
For this column, I want to replace all Left_only values to Yesterday And Right_only To Today
I use this code line:
DF.loc[df[‘Remarks’] == ‘Left_only’, ‘Remarks’] = ‘Yesterday’
Similarly, for the other one. But I get this error:
Cannot setitem on a Categorical with a new category (Yesterday), set the categories first
What am I doing wrong ?
>Solution :
# create a dictionary to map the two values
d={'Left_only': 'Yesterday', 'Right_only':'Today'}
df['Remarks']=df['Remarks'].map(d)
df
0 Yesterday
1 Today
2 Yesterday
3 Today
Name: Remarks, dtype: object