Skip to main content

Python Pandas Series: index

Series is a 1-D ndarray with axis labels. The label should be of a hashable type. The data aligns automatically by labels or index. The index can be generated automatically.

Pandas Series.index attribute is used to get or set the index labels of the given Series object. It is a sequence of numbers. It starts with 0 and end at an integer that is one less than the length of the entire sequence.

Example

import pandas as pd

data=['P','Y','T','H','O','N']
a=pd.Series(data)

a.index=['Word 1','Word 2','Word 3','Word 4','Word 5','Word 6']
print(a)

Output:

Word 1    P
Word 2    Y
Word 3    T
Word 4    H
Word 5    O
Word 6    N
dtype: object
Submitted by devanshi.srivastava on November 2, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.