Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Change the value of a column based on the value of another column with pandas

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.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Try something like:

df['value'][df['Currency'] == 'GBP'] = df['value'][df['Currency'] == 'GBP'] * GBP_factor
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading