SyntaxFix
Write A Post
Hire A Developer
Questions
Here is a solution through list comprehension. cols is the list of columns to get index for:
[df.columns.get_loc(c) for c in cols if c in df]