Home > Net >  Change the value of a column based on the value of another column with pandas
Change the value of a column based on the value of another column with pandas

Time:04-28

To clarify I'll give an example:

  • Dataframe has 2 columns: Currency and Price
  • Currency has 3 unique values: EUR, GBP, USD
  • I need to set the prices, as they are all in USD
  • I need to multiply those values that are GBP and EUR with another double, i.e. 1.15 and 1.5 respectively.

CodePudding user response:

Try something like:

df['value'][df['Currency'] == 'GBP'] = df['value'][df['Currency'] == 'GBP'] * GBP_factor
  • Related