You can use the set_index() function of the pandas dataframe. This function sets the DataFrame index (row labels) using one or more existing columns of the DataFrame. The index can replace the existing index or expand on it.
Here is an example:
>>> import pandas as pd>>> df=pd.DataFrame({'A':[1,2,3,4,5], 'B':[10,20,30,40,50], 'C':[11,12,13,14,15]})>>> df A B C0 1 10 111 2 20 122 3 30 133 4 40 144 5 50 15
Using one column
>>> df.set_index('C') A BC 11 1 1012 2 2013 3 3014 4 4015 5 50
Using multiple columns
>>> df.set_index(['C','A']) BC A 11 1 1012 2 2013 3 3014 4 4015 5 50
Expand the existing index
>>> df.set_index('C', append=True) A B C 0 11 1 101 12 2 202 13 3 303 14 4 404 15 5 50