When you might be looking to find multiple column matches, a vectorized solution using searchsorted method could be used. Thus, with df as the dataframe and query_cols as the column names to be searched for, an implementation would be -
def column_index(df, query_cols):
cols = df.columns.values
sidx = np.argsort(cols)
IDs = return sidx[np.searchsorted(cols,query_cols,sorter=sidx)]
Sample run -
In [234][162]: df
Out[234]Out[162]:
apple banana pear orange peach
0 8 3 4 4 2
1 4 4 3 0 1
2 1 2 6 8 1
In [235][163]: query_cols
Out[235]:column_index(df, ['peach', 'banana', 'apple']
In [236]: IDs)
Out[236]Out[163]: array([4, 1, 0])