I have dataframe that contains two columns of different classes diamond, gold and silver.
class_pd = pd.DataFrame({'old_class':['gold', 'gold' , 'silver'],
'new_class':['diamond', 'silver', 'silver']})
I want to create a new column that shows wither the classes was Upgraded or Downgraded
What I have tried
I wrote the below function to set the rules
def status_desc(class_pd, old_class, new_class):
if ((class_pd['old_class'] == 'gold') & (class_pd['new_class'] == 'diamond') or \
(class_pd['old_class'] == 'silver') & (class_pd['new_class'] == 'diamond') or \
(class_pd['old_class'] == 'silver') & (class_pd['new_class'] == 'gold')):
val = 'Upgrade'
elif ((class_pd['old_class'] == 'diamond') & (class_pd['new_class'] == 'gold') or \
(class_pd['old_class'] == 'diamond') & (class_pd['new_class'] == 'silver') or \
(class_pd['old_class'] == 'gold') & (class_pd['new_class'] == 'silver')):
val = 'Downgrade'
else:
val = 'NA'
Then I tried to apply the function to my dataframe using the below method
class_pd['class_desc'] = class_pd.apply(lambda x: status_desc(class_pd['old_class'], class_pd['new_class']), axis=1)
Error
I get this error
TypeError: status_desc() missing 1 required positional argument: new_class
Desired Output
class_pd = pd.DataFrame({'old_class':['gold', 'gold' , 'silver'],
'new_class':['diamond', 'silver', 'silver'],
'class_desc':['Upgrade','Downgrade', 'NA']})