What does axes in the pandas series mean?


The “axes” is an attribute of the pandas series object, this attribute is used to access the group of index labels in the given Series. It will return a python list of index labels.

The axes attribute collects all the index labels and returns a list object with all index labels in it.

Example 1

import pandas as pd

# create a sample series
s = pd.Series({'A':123,'B':458,"C":556, "D": 238})

print(s)

print("Output: ")
print(s.axes)

Explanation

In the following example, we initialized a Series with some data. Then we called the axes property on the series object.

Output

A   123
B   458
C   556
D   238
dtype: int64

Output:
[Index(['A', 'B', 'C', 'D'], dtype='object')]

The output of the initial series object, and the output of the axes attribute, can be seen in the above output block.

The output for the axes attribute is a list which is holding the index labels A, B, C, D of the series.

Example 2

import pandas as pd

# create a sample series
s = pd.Series([37,78,3,23,5,445])

print(s)

print("Output: ")
print(s.axes)

Explanation

In this example, we have initialized a series object without specifying the index, So here the default index will be created for the series object. And the values are assigned through a python list with integer elements.

Output

0   37
1   78
2   3
3   23
4   5
5   445
dtype: int64

Output:
[RangeIndex(start=0, stop=6, step=1)]

We got the python list object as an output for the axes property and the data present in the list is range values which represent the index label of the series.

Updated on: 09-Mar-2022

144 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements