I have two series. I want to subtract one data frame from another data frame, even if they have a different number of columns.
>df1
index 0 1 2 3 4 5
TOTAL 5 46 56 110 185 629
>df2
index 1 2 3 4 5
Use 25 37 86 151 512
I would suggest that subtracting two data frames with different dimensions will only result in NaNs in inconsistent columns (in this case, column 0). The remaining columns will be the result of df1 [1] -df2 [1], df1 [2] -df2 [2], etc.
>df1 - df2
index 0 1 2 3 4 5
TOTAL NaN 21 19 24 34 117
But this is not so. Is this what happens when I subtract dataframes?
>df1 - df2
index 0 1 2 3 4 5
Use NaN NaN NaN NaN NaN NaN
TOTAL NaN NaN NaN NaN NaN NaN
I also tried just subtracting the values:
>df1.values - df2.values
Traceback (most recent call last):
File "<ipython-input-376-1dc5b3b4ad3e>", line 1, in <module>
total_drugs.values-(restraints_drugs.values+norestraints_drugs.values)
ValueError: operands could not be broadcast together with shapes (1,6) (1,5)
What am I doing wrong? I am using pandas 0.18.
ale19 source
share