pandas name index code example
Example 1: rename dataframe index column pandas
df.index.names = ['new_name']
Example 2: how to give column names in pandas when creating dataframe
df_new = df.rename(columns={'A': 'a'}, index={'ONE': 'one'})
print(df_new)
print(df)
Example 3: python - give a name to index column
df.index.name
df.index.name = 'my_column_name'
Example 4: dataframe get index name
In [7]: df.index.name
Out[7]: 'Index Title'
In [8]: df.index.name = 'foo'
In [9]: df.index.name
Out[9]: 'foo'
In [10]: df
Out[10]:
Column 1
foo
Apples 1
Oranges 2
Puppies 3
Ducks 4