Find & Replace Equivalent with Pandas

Python

In this example we replace each value 1 with 'A' and 2 with 'B' in the id column.

 1|  df.loc[df['id'] == 1, 'id'] = 'A'
 2|  df.loc[df['id'] == 2, 'id'] = 'B'
Did you find this snippet useful?

Sign up for free to to add this to your code library