How to get the index of a Pandas DataFrame column from its name in Python

Given the name of a column in a DataFrame, its index can be obtained.

Solution for How to get the index of a Pandas DataFrame column from its name in Python : You can use pd.DataFrame.get_loc() to get the index of a DataFrame column from its name Use pd.DataFrame.columns to obtain an object containing all column names in pd.DataFrame. Call pd.Index.get_loc(key) with this result as pd.Index and a column name as key to get the index of the column.


how-to-get-the-index-of-a-pandas-dataframe-column-from-its-name-in-python