I'm trying to apply an if-then statement over multiple columns, then have the results of that if-then statement outputted to new columns. My data looks like this:
AtoB BtoC CtoD
240 600 1000
-30 540 540
50 -50 0
0 0 -10
My desired output is:
AtoB_C BtoC_C CtoD_C
C C C
E C C
C E S
S S E
The idea is that the result of the if-then statement is stored in these new variables and the original variables will still be present. The variables to be evaluated are in the "Results" list and the output variables (which have nothing in them at the moment) are in "Result_Correct" list My code is:
Result = ['AtoB','BtoC','CtoD']
Result_Correct = ['AtoB_C','BtoC_C','CtoD_C']
for row in DF[Result]:
if row > 0:
[Result_Correct].append('c')
elif row == 0:
[Result_Correct].append('s')
else:
[Result_Correct].append('e')
DF[Result_Correct] = [Result_Correct]
When I try running this, I get the message "'>' not supported between instances of 'str' and 'int'". How can I make this work? Thanks!