使用Easymoney和Pandas进行货币转换 [英] Currency conversion with easymoney and pandas

查看:136
本文介绍了使用Easymoney和Pandas进行货币转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将具有不同货币的值转换为"USD"货币.我尝试了easymoneyCurrencyConvertor软件包,但它们似乎不适用于数据框python.

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.

如果我使用iloc逐行进行转换似乎很正常,但这会花费大量时间.

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

推荐答案

您需要 apply axis=1用于按行处理:

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)

这篇关于使用Easymoney和Pandas进行货币转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆