Sample DF:
I have a df with columns like Zone
, New_Zone
, Country
, New_Region
& Currency
Currency
column has values like EUR
, AUD
, BLR
,RUB
Zone
columns has values like EU
, Africa
, NAZ
New_Zone
has values like EU
, Europe
, EUROPE
, Africa
, NAZ
, AFRICA
Country
has values like Australia
, Brazil
, Russia
, Ukraine
, USA
New_Region
has values like Australia
, Brazil
, USA
So, columns Zone
and New_Zone
contains almost similar values and New_Region
and Country
almost similar values
Ask:
I want to make a new column called Currency_Match
with below conditions:
If Zone is EU OR(logical) New_Zone is EU, Europe or EUROPE AND(logical)Currency is
EUR
then Yes else NoIf Country is Australia OR(logical) New_Region is Austraila AND(logical) Currency is
AUD
then Yes else NoIf Country is BrazilOR(logical) New_Region is Brazil AND(logical) Currency is
BLR
then Yes else NoIf Country is KoreaOR(logical) New_Region is koreaAND(logical) Currency is
KRW
then Yes else NoIf Zone is Africa OR(logical) New_Zone is Africa or AFRICA, AND(logical)Currency is
NGN
then Yes else No
6 If Zone is NAZ OR(logical) New_Zone is NAZ, AND(logical)Currency is USD
then Yes else No
7 If Country is Russia , Ukraine OR(logical) New_Region is RussiaAND(logical) Currency is RUB
then Yes else No
I have overall 7 conditions like these above ones
Code:
df['Currency_Match']=df.apply(lambda row: "Yes" if (((row['Zone'] == "EU")|(row['New_Zone'] =='Europe')|(row['New_Zone'] =='EU')|(row['New_Zone'] =='EUROPE'))
& (row["Contract - Original Currency Code"] == "EUR"))
else 'No',axis=1)
Problem:
Above code works well but when I write the other conditions like this it updates the column again and again.
Is their any other approach I can do this and also less cumbersome than this