I am struggling with I think with a relatively easy problem.
Below is example of two rows in the dataframe.
df_example.iloc[0]=
date: 24/03/2020
time: 10:10:10
currency: GBX
price: 100
df_example.iloc[1]=
date: 24/03/2020
time: 11:10:10
currency: EUR
price: 20
I would like to simply divide the GBX last price value in the first row however not affect the second row within my data frame. The methods I have tried converts the price of the second row as a NaN or python throws a number of alerts/warnings which I would like to avoid.
The method I have ended up with is a For loop which iterates through each line and coverts all GBX to their major GBP and leaves all EUR values the same, resulting in no NaN values. However, this takes an extremely long time to iterate through each row.
Methods: Working:
for i in range(len(df.index)-1):
if df['currency'].iloc[i] == 'GBX':
df['price'].iloc[i] = float(df['price'].iloc[i]) / 100
#print(df['Last Price'].iloc[i])
else:
df['price'].iloc[i] = float((df['price'].iloc[i]))
#print(df['Last Price'].iloc[i])
Not Working:
1. df['Last Price'] = df[df['Currency']==GBX]['Last Price'].div(100)
2. df['Last Price'] = df[df['Currency']==GBX]['Last Price'].apply(lambda x: x/100)
3. creating two different dataframes and trying to merge throughs python index warnings
Please let me know if you require any further information.
Thank you.