我有两个数据帧:
价格
date price currency rate
13-04-2018 34 EUR
14-04-2018 23 USD
15-04-2018 64 PLN
exchange_rates
date currency rate
13-04-2018 EUR 4
13-04-2018 USD 3
13-04-2018 PLN 1
13-04-2018 EUR 3,9
13-04-2018 USD 2,8
13-04-2018 PLN 1
13-04-2018 EUR 4,3
13-04-2018 USD 3,2
13-04-2018 PLN 1
我想在价格DF中添加列,从汇率数据框中获取费率...应选择正确的汇率(对于正确的日期和正确的货币)。我尝试使用match(),np.where和iloc,但没有成功。
答案 0 :(得分:0)
import pandas as pd
prices = <ur prices dataset>
exchange_rates = <ur exchange rates dataset>
output = pd.merge(prices, exchange_rates, on=["date", "currency"], how="inner")
print(output)