Given a dataframe such as
df = pd.DataFrame({1: [10,20,30,40], 2: [50,60,70,80], 3: [90,100,110,120], "select": [2, 3, 1, 1])
I can get a series of values selected from each row want to select values in each row corresponding to the column index given in the select column, like this:
df.apply(lambda r: r[r.select], axis=1) # 50, 100, 30, 40
Is there a better way to do this that doesn't rely on apply?