This should be obvious but I cannot make it work.
I have a pandas dataframe A with column and index names:
A = pd.DataFrame([[10, 20], [4, 5], [20, 30]],
columns = ['col1', 'col2'],
index = ['row1', 'row2', 'row3'])
col1 col2
row1 10 20
row2 4 5
row3 20 30
Then I have another dataframe B with only one row (without name, so default 0) and same column names as A
B = pd.DataFrame([[100, 200]],
columns = ['col1', 'col2'])
col1 col2
0 100 200
I want to add A+B so I obtain a new dataframe C:
col1 col2
row1 110 220
row2 104 205
row3 120 230
The most obvious thing would be to do:
A + B
col1 col2
row1 NaN NaN
row2 NaN NaN
row3 NaN NaN
0 NaN NaN
Then I tried
A.sum(B)
TypeError: 'DataFrame' objects are mutable, thus they cannot be hashed
Am I missing something? numpy arrays will do the job super easily, what's wrong with dataframes?
I know the index names don't match, but I want to apply the vector B to all rows of A.