Keen to know if it's possible to reproduce the following logic in Python, in one line, without creating a function.
z = IF (y-x) = 0 THEN a ELSE (y-x)
Using this df:
df = pd.DataFrame({'x': [10, 22, 31, 43, 57, 99, 65, 74, 88],
'y':[10, 50, 31, 66, 57, 199, 75, 80, 100]})
which looks like:
x y
0 10 10
1 22 50
2 31 31
3 43 66
4 57 57
5 99 199
6 65 75
7 74 80
8 88 100
To produce the following output:
x y z
10 10 10
22 50 28
31 31 31
43 66 23
57 57 57
99 199 100
65 75 10
74 80 6
88 100 12
I have attempted the following but this returns a syntax error.
z = if(y - x) == 0: a else: (y - x)
I appreciate there are similar questions but I haven't found anything that is applicable to my use case or has a sufficient explanation such that I can repurpose the code.