Given two lists f=['a','b','c','d'] and g=['a','c'], I can produce [0,2]=indexes(f,g) with
def indexes(f,g):
return [f.index(x) for x in g]
is there a better way?
Motivation:
For a numpy matrix X, I want to extract some columns, so I want to replace pd.DataFrame(X,columns=f)[g].values with X[:,indexes(f,g)].