xxxxxxxxxx
#cree un indice par defaut sur la base de donnee
df.reset_index()
xxxxxxxxxx
df.set_index('col') # Set a single column as index
df.set_index(['col1','col2']) # Create multi-level index
xxxxxxxxxx
#Python 3
#Declare list of index
#and just assign it to the existing dataframe
separate_list = [1,2,3,4,5]
df.index = separate_list
xxxxxxxxxx
import pandas as pd
# Assuming the dataframe is already created and named 'df'
# Set a single column as the index
df.set_index('column_name', inplace=True)
# Set multiple columns as the index (creating a MultiIndex)
df.set_index(['column_name1', 'column_name2'], inplace=True)
# Reset the index to the default integer index
df.reset_index(inplace=True)
xxxxxxxxxx
>>> df.set_index('month')
year sale
month
1 2012 55
4 2014 40
7 2013 84
10 2014 31