0

In the example below (df name 'statement', column name 'product'), I want product 1 to be changed to product 2. I achieve this on the first line, but then the second line changes it from product 2 to product 18. Later, it changes from product 18 to product 13. How to perform all the loc operations given below in parallel. Instead of performing one after the other.

Example:

statement.loc[statement['product'] == 1, 'product'] = 2
statement.loc[statement['product'] == 2, 'product'] = 18
statement.loc[statement['product'] == 18, 'product'] = 13
Nick ODell
  • 15,465
  • 3
  • 32
  • 66
jray
  • 1

1 Answers1

1

I would use replace instead of loc filtering to do this

mappings = {1:2, 2:18, 18:13}
statement['product'] = statement['product'].replace(mappings)
jcaliz
  • 3,891
  • 2
  • 9
  • 13