Skip to content
Advertisement

Subtracting the values in another DataFrame from every column in a pandas DataFrame

I have two DataFrames of 20 rows and 4 columns. The names and value types of the columns are the same. One of the columns is the title, the other 3 are values.

JavaScript

Now I would like to create 3 separate tables/lists subtracting each value of df1.col1 - df2.col1 | df1.col2 - df2.col2 | df1.col3 - df2.col3. For df1.col1 - df2.col1 I expect an output that looks something among the lines of:

JavaScript

I tried to create a for loop using the following code:

JavaScript

In return, I received an output for score_col1 looking like this:

JavaScript

Can someone help me to obtain the expected output?

Advertisement

Answer

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement