vendredi 7 juillet 2017

How to use if statement and perform the following operation?

How to use if loops and perform the following condition:

for example if i have the following datatype,

id    count A    count B    variable A     variable    sum
AAA    6           34         AA              AA        10
123    15          19         RA              RA        25
AAA    61          04         AA              AA        85
123    1           91         RS              RS        35
123    66          89         RA              RA        25
AAA    45          41         SP              SP        55
123    62          39         SS              SS        45

For the same id, if variable A and variable B are same and not same, i would like to perform this operation.

if variable A = variable B

df = df.assign(result = np.where(df.sum < 50, df.shift(1).count A, df.count A))

if variable A != variable B

df = df.assign(result = np.where(df.sum > 50, df.shift(1).count A, df.count A))

Aucun commentaire:

Enregistrer un commentaire