I have a dataframe with columns currency, loan_amnt. And variables with currency values for each month. I have to check if currency equal to usd, then divide loan_amnt to usd currency value and save in new column. Same for eur and jpy. But if currency is uzs, then pass it. I wrote function but it didn't work.
sample df:
currency loan_amnt
0 usd 100000
1 eur 150000
2 jpy 85000
3 uzs 90000
4 usd 50000
5 eur 65000
variables:
feb_usd = 9563,33
feb_eur = 10541,66
feb_jpy = 87,52
my function:
def currency_diff(data, usd, eur, jpy):
for i, row in data.iterrows():
currency= row['currency']
loan_amnt= row['loan_amnt']
if currency== 'USD':
return loan_amnt/ usd
elif currency== 'EUR':
return loan_amnt/ eur
elif currency== 'JPY':
return loan_amnt/ jpy
else:
loan_amnt
df['nominal'] = df.apply(lambda x: currency_diff(x, feb_usd, feb_eur, feb_jpy))
It didnt work. Any help would be much appreciated! Thank you.