I have a DataFrame that looks like this:
FirstDF=
C
A B
'a' 'blue' 43
'green' 59
'b' 'red 56
'c' 'green' 80
'orange' 72
Where A and B are set as indexes. I also have a DataFrame that looks like:
SecondDF=
A B
0 'a' 'green'
1 'b' 'red'
2 'c' 'green'
Is there a way I can directly query the first DataFrame with the last one, and obtain an output like the following?
C
59
56
80
I did it by iterating over the second DataFrame, as shown below, but I would like to do it using pandas logic instead of for loops.
data=[]
for i in range(SecondDF.shape[0]):
data.append(FirstDF.loc[tuple(SecondDF.iloc[i])])
data=pd.Series(data)