I am trying to convert values with different currency to "USD" currency. I tried easymoney
and CurrencyConvertor
packages but those do not seem to work with dataframe python.
It seems working if I do conversion row by row using iloc
but that is taking an awful lot of time.
from easymoney.money import EasyPeasy
ep = EasyPeasy()
ep.currency_converter(df_train['goal'], from_currency=df_train['currency'], to_currency="USD")
Error:
TypeError: invalid type comparison
You need apply
with axis=1
for processing by rows:
from easymoney.money import EasyPeasy
ep = EasyPeasy()
df_train['converted'] = df_train.apply(lambda x: ep.currency_converter(x['goal'], from_currency=x['currency'], to_currency="USD"), axis=1)