I have a pandas DataFrame, then I apply a function to a bunch of columns and I get a new result column. Then I want to be able to check the results of the new column with the original column values.
a b
0 0 0
1 0 1
2 1 0
3 1 1
I want a one-liner that without changing the original df would return this (let's say I'm applying xor function):
a b xor
0 0 0 0
1 0 1 1
2 1 0 1
3 1 1 0
What I'm doing now is (I work in the shell, so 2nd line prints the 'df'):
df['result'] = df.apply(xor, axis=1)
df
(foo gets a 'row' and let's say it does something with all the columns, so I'm not aiming to something column-specific, in the end I want to see all the original columns and the result column next to them).
I don't like this option because it's 2-step AND changing the original dataframe. My goal is to check the function again and again, so I want to be able to show the result next to the original values.
Is there an easy 1-step straightforward way of doing it?
Thanks,