-1

I am having below table

Particulars            DC    Amt
AA                     D      50
BB                     D      20
CC                     C      30
DD                     D      20
EE                     C      10

I require below output, if DC column is having "D" it should have same amount in "Amt" column and if DC column is "C" should multiply by (-1) with Amt amount.

Particulars            DC    Amt      TTL
AA                     D      50      50
BB                     D      20      20
CC                     C      30     (30)
DD                     D      20      20
EE                     C      10     (10)
Ajith
  • 1,447
  • 2
  • 17
  • 31
Juzar Para
  • 43
  • 6

1 Answers1

3

You can use np.where:

df['TTL'] = np.where(df.DC == 'D', df.Amt, -1*df.Amt)
ignoring_gravity
  • 6,677
  • 4
  • 32
  • 65