0
所以我有一個DataFrame
與幾千行包含人工外匯交易數據。前十行是這樣的:大數據集上的循環次優
我想遍歷這個集合,併爲每一行,計算CommonCurrency
在這種情況下將是美元。因此,對於每一行,我走在CurrencyPair
,DeskRate
和OrderQty
列和計算CommonCurrency
:
for i in range(len(order_data)):
if (order_data['CurrencyPair'][i] == 'GBP/USD'):
order_data['CommonCurrency'][i] = order_data['DeskRate'][i] *
order_data['OrderQty'][i]
elif (order_data['CurrencyPair'][i] == 'AUD/USD'):
order_data['CommonCurrency'][i] = order_data['DeskRate'][i] *
order_data['OrderQty'][i]
elif (order_data['CurrencyPair'][i] == 'EUR/USD'):
order_data['CommonCurrency'][i] = order_data['DeskRate'][i] *
order_data['OrderQty'][i]
elif (order_data['CurrencyPair'][i] == 'USD/CHF'):
order_data['CommonCurrency'][i] = order_data['DeskRate'][i]/
order_data['OrderQty'][i]
elif (order_data['CurrencyPair'][i] == 'EUR/GBP'):
order_data['CommonCurrency'][i] = #different calculation
這似乎並不喜歡做的正確的方式,特別是沒有如果有大量不同的貨幣對。我遇到的另一個問題是,當我到達EUR/GBP
時,因爲現在我必須同時獲得DeskRate
和EUR/USD
,我看不出如何使用此方法。
任何提示?