I have below dataframe
df = pd.DataFrame({'col1': {0: '4', 1: '4', 2: '2'},'col2': {0: 'USA', 1: 'England', 2: 'Japan'}})
>>> df
col1 col2
0 4 USA
1 4 England
2 2 Japan
and I have below dictionary
dict_1 = {"USA" : 'Washington',"Japan" : 'Tokyo',"England" : 'London'}
I want to replace values in col2 using dict_1 but replace in rows where col1 == 2
Desired output is as below
col1 col2
0 4 USA
1 4 England
2 2 Tokyo
I tried below method but it doesnt do anything
df.loc[df['col1'] == '2', 'col2'].replace(dict_1,inplace=True)