How can I create df3 according to df1 and df2?
df1 = pd.DataFrame([[1,2,3],[10,20,30],[100,200,300]], index=['a','b','c'],columns=['A','B','C'])
df2 = pd.DataFrame([['A','C'],['B','A'],['C','B']],index=['a','b','c'],columns=[0,1])
df3 = pd.DataFrame([[1,3],[20,10],[300,200]], index=['a','b','c'],columns=[0,1])
Here is my code,
df1.apply(lambda x: x.loc[df2.loc[x.name,:]], axis=1)
This is df1
This is df2
This is df3