Steven
Steven

Reputation: 53

Iterate over column to convert currency with the forex-python package

I have a column ['currency'] and another one ['amount']. The column ['currency'] contains objects in this format: USD, EUR, SEK, AUD, etc.

I would like to convert all the ['amount'] values into USD by converting all the other currencies, and print the new conversion in a new column, but I got stuck at this point:

    import pandas as pd
    from forex_python.converter import CurrencyRates

    c = CurrencyRates()

    y = ['currency']
    x = ['amount']

    for column in df['amount']:
       c.get_rate('USD', x)

Should I link every currency symbol with the respective amount?

Upvotes: 0

Views: 370

Answers (1)

gtomer
gtomer

Reputation: 6574

If you have a df then this is the way to iterate over the rows:

for index, row in df.iterrows():
    c.get_rate(row['currency'], row['amount'])

I am not familiar with the get_rate function.

Upvotes: 1

Related Questions