迭代列以使用forexpython包转换货币

2024-06-11 16:25:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个列['currency'],另一个列['amount']。列['currency']包含以下格式的对象:美元、欧元、瑞典克朗、澳元等

我想通过转换所有其他货币将所有['amount']值转换为美元,并在新列中打印新的转换,但我在这一点上遇到了困难:

    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)

我是否应该将每个货币符号与各自的金额联系起来


Tags: 对象fromimportpandasforas格式货币