I have a dataframe in pandas called as df_A which in real-time has more than 100 columns.
And, I have another dataframe df_B in which two columns gives me what columns do I need from the df_A
A reproducible example has been given below,
import pandas as pd
d = {'foo':[100, 111, 222],
'bar':[333, 444, 555],'foo2':[110, 101, 222],
'bar2':[333, 444, 555],'foo3':[100, 111, 222],
'bar3':[333, 444, 555]}
df_A = pd.DataFrame(d)
d = {'ReqCol_A':['foo','foo2'],
'bar':[333, 444],'foo2':[100, 111],
'bar2':[333, 444],'ReqCol_B':['bar3', ''],
'bar3':[333, 444]}
df_b = pd.DataFrame(d)
As it can be seen df_b in the above example, the values under ReqCol_A and ReqCol_B is what I am trying to get from df_A
so, my expected output will have three columns from df_A. The three columns will foo foo2 and bar3.
df_C will be the expected output and it will look like
df_C
foo foo2 bar3
100 110 333
111 101 444
222 222 555
Please help me with this. I am struggling to get this.