Said Tahmazov
Said Tahmazov

Reputation: 67

Multiple condition in pandas

I have a dataset and contain price and currency. There are 3 currency dollar, euro, azn and it has 25000 columns. How to make price in azn currency I must multiply all dollar prices to 1.7 and euros to 1.9. I use where in pandas but I can do one of them as this:

df['price_new'] = df.price.where(df.currency=='AZN', df.price*1.7)

but this code works for only one condition and change only dollar to azn.

Upvotes: 1

Views: 76

Answers (1)

BENY
BENY

Reputation: 323226

You are looking for np.select

con1=df.currency=='AZN'
con2=...
v1=df.price*1.7
v2=...
df['price_new'] = np.select([con1,con2],[v1,v2])

Upvotes: 1

Related Questions