let's suppose I have one dataframe with at least two columns col1 and col2. Also I have another dataframe whose column names are values in col 1 and whose indices are values in col2.
import pandas as pd df1 = pd.DataFrame( {'col1': ['x1', 'x2', 'x2'], 'col2': ['y0', 'y1', 'y0']}) print(df1) col1 col2 0 x1 y0 1 x2 y1 2 x2 y0 print(df2) y0 y1 x1 1 4 x2 2 5 x3 3 6 Now I wish to add col3 that gives me the value of the second dataframe at index of col1 and in column of col2. The result should look like this:
col1 col2 col3 0 x1 y0 1 1 x2 y1 5 2 x2 y0 2 Thank you all!