How to set a column as the index of a Pandas DataFrame in Python

Setting a column as the index of a pandas.DataFrame turns the elements in the column into row indices, then removes the column.

Solution for How to set a column as the index of a Pandas DataFrame in Python : You can use pandas.DataFrame.set_index() to set a column as the index Call pandas.DataFrame.set_index(keys) with keys a the name of the column to convert to an index.

The name of the column is converted to an index name. To remove the index name, call del pandas.DataFrame.index.name.

del df.index.name


how-to-set-a-column-as-the-index-of-a-pandas-dataframe-in-python