Skip to content
Advertisement

Combinations of all dataframe columns in python

I have three data frames that have the same index (Countries). I need to find all the combinations of the three data frames, create new columns with the data frames. Under each of those columns I will have the multiplication of the values from those combinations.

JavaScript
JavaScript

I tried to use the MultiIndex.from_product

JavaScript

but the results is only for the titles:

JavaScript

I need to have the values for each countries, so it should look like this (3 x 2x 2) = 12 combinations:

JavaScript

How can I create the new columns and the combinations of the three dataframes?

Advertisement

Answer

You could do the following:

JavaScript

Output:

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