0

I want to set the same index on different dataframes which have the same rows on some columns.

The dataframe has 10,000 rows, so I'll simplify it. For example:

df1:

Country Coin Market    Type    x    y   z
US      US$  Internal  Budget  1    2   3
US      US$  External  Budget  4    5   6
US      US$  Internal  Budget  7    8   9
Mexico  MXN$ External  Budget  1    2   3

df2:

Country Coin Market    Type    x    y   z
Mexico  MXN$ External  Real    1    6   3
US      US$  Internal  Real    2    3   5
US      US$  Internal  Real    5    8   7
US      US$  External  Real    1    7   4

So I would like to set the same index for rows that match 'Country', 'Coin' and 'Market', so then I could make some calculations between 'x', 'y' and 'z' for real vs budget values after sorting by index.

I need to set index because some rows on df1 are missing from df2.

Any help would be appreciated.

  • Merge on the wanted columns – mozway May 18 '22 at 21:30
  • I dont want to merge them since I perform calculations on different dataframes – felipemedlev May 18 '22 at 21:46
  • Merge them to obtain an temporary aligned dataframe that you can use for your calculations You can get well `set_index` as well (no need to sort, pandas aligns the dataframes when performing computations). In any case you should provide a specific issue of you really don't manage (code, detailed logic, specific issue, and expected output). – mozway May 19 '22 at 02:01

0 Answers0