I have a pandas DataFrame, something like:
col1 col2 col3 col5
NaN 1 2 8
2 NaN 4 8
4 NaN 4 8
I want to do two t
Here's one approach.
You could create newcol1 by sum(axis=1)
In [256]: df['newcol1'] = df[['col1', 'col2']].sum(axis=1)
In [257]: df
Out[257]:
col1 col2 col3 col5 newcol1
0 NaN 1 2 8 1
1 2 NaN 4 8 2
2 4 NaN 4 8 4
Then use df.sub() on axis=0
In [258]: df[['newcol1', 'col3']].sub(df['col5'], axis=0)
Out[258]:
newcol1 col3
0 -7 -6
1 -6 -4
2 -4 -4