I have two dataframes, A and B. Each has the same dimensions and same columns. Lets say I want to substract both dataframes (dfB-dfA) if the values of the rows in the first three columns match. Below is an example.
dfA
dfB
NewDF
In the example above, it is easy because the columns are organised, however, in reality both dataframes are much bigger.
I tried with a for loop but it didn't work. I would much appreciate your help.
Best regards.
CodePudding user response:
Pandas is smart enough to take the indices into account. Just convert the columns you want to match into the index and perform your operation as NewDF = dfA-dfB