1

Im new to python and pandas I have a csv with data which im able to read and extract data using pandas as shown below

data = pd.read_csv("train.csv")

I have many columns below is the columns in question

enter image description here

Here i want to convert the price column into USD equivalent for all the entries. following is the code which i tried

currencyToUSD = {
"USD": 1,
"AUD": 0.7,
"EUR": 1.12,
"HKD": 0.13,
"INR": 0.014,
"KRW": 0.00085
}
for row in data.itertuples():
   data[row.index]['price'] = row.price*currencyToUSD[row.currency]

It throws errors, what i want to achieve is to modify the 'price' column based on the value of 'currency' column. Guide me with the right way to achieve this

Thanks in advance

1 Answer 1

1

Here itertuples should be omit for improve performance, use Series.map for new Series for multiple column price:

data['price'] = data.price*data.currency.map(currencyToUSD)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.