I'm trying to define a new column ['Actual Loss'] that is dependent on the value of another column ['Loss'] If the value of ['Loss'] is less than zero then multiply it by -1 If the value of ['Loss'] is greater than zero then multiply it by 0
df1 = Investor, Loss
Tom, -100
Barry, 100
expected:
df1 = Investor, Loss, Actual Loss
Tom, -100, 100
Barry 100, 0
Code = if len (df) < 0 : df['Actual Loss'] = df.apply(lambda x: x['Loss']*-1 if x['Loss'] <0 else x['Loss')*0)
Aucun commentaire:
Enregistrer un commentaire