I would like to subtract all rows in a dataframe with one row from another dataframe. (Difference from one row)
Is there an easy way to do this? Like df-df2)?
df = pd.DataFrame(abs(np.floor(np.random.rand(3, 5)*10)),
... columns=['a', 'b', 'c', 'd', 'e'])
df
Out[18]:
a b c d e
0 8 9 8 6 4
1 3 0 6 4 8
2 2 5 7 5 6
df2 = pd.DataFrame(abs(np.floor(np.random.rand(1, 5)*10)),
... columns=['a', 'b', 'c', 'd', 'e'])
df2
a b c d e
0 8 1 3 7 5
Here is an output that works for the first row, however I want the remaining rows to be detracted as well...
df-df2
a b c d e
0 0 8 5 -1 -1
1 NaN NaN NaN NaN NaN
2 NaN NaN NaN NaN NaN