Efficient way to get indices of column-labels from pd.DataFrame
<p>I have this method where I grab the columns from a <code>pandas dataframe</code> depending on the labels but indexing via <code>numpy</code> is much faster.  </p>

<p><strong>Is there a way in <code>pandas</code> or <code>numpy</code> to go from column labels to column indices without iterating?</strong> </p>

<pre><code>DF_var = pd.DataFrame(np.random.random((5,10)), columns=["attr_%d" % _ for _ in range(10)])
query_cols = ["attr_2","attr_5","attr_6","attr_0"]
want_idx = [0,2,5,6]

# Something like np.where w/o iterating through? 
# np.where(query_cols in DF_var.columns)
# TypeError: unhashable type: 'list'

# np.where(x in DF_var.columns for x in query_cols)
# (array([0]),)


long_way = list()
for i, label in enumerate(DF_var.columns):
    if label in query_cols:
        long_way.append(i)
# print(sorted(long_way))
# [0, 2, 5, 6]
</code></pre>

<p><a href="https://i.stack.imgur.com/mgZZQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mgZZQ.png" alt="enter image description here"></a></p>