Python Pandas Objects: Index.names

Profile picture for user devanshi.srivastava
Submitted by devanshi.srivastava on

Pandas Series can have a name and these are set as columns names in dataframe. The index can also have its own name, these names are known as index names.

Example

import pandas as pd

books_names=['Don Quixote','Lord of the Rings','Pinocchio','And Then There Were None']
books_series=pd.Series(books_names)#series
books_series.name="Famous Books"#index name

print(books_series)

Output:

0                 Don Quixote
1           Lord of the Rings
2                   Pinocchio
3    And Then There Were None
Name: Famous Books, dtype: object

Here in the above example "Famous Books" is the index name.