I'm having a dataframe and a dictionary based on dictionary values that are present in col1 need to replaced. I tried but it's not changing. What is the efficient way of doing it. Thank You.
df = pd.DataFrame({'col2': {0: 'a', 1: 2, 2: np.nan}, 'col1': {0: 'w', 1: 1, 2: 2}})
di = {1: "A", 2: "B"}
df
col1 col2
0 w a
1 A 2
2 B NaN
Expected output:
df.replace({"col1": di})
col1 col2
0 w a
1 1 2
2 2 NaN