How to return a list representing the axes of a given dataframe

Overview

The DataFrame.axes attribute in Pandas is used to return a list of values representing the axes of a given DataFrame. It also returns the labels of the row and columns axis as the only member.

Syntax

DataFrame.axes attribute
Syntax for the DataFrame.axes attribute in Pandas

Parameters

This attribute takes no parameter value.

Return value

This attribute returns a list showing the labels of the row and column axis labels as the only members in that order.

Example

import pandas as pd
# creating a dataframe
df = pd.DataFrame({'AGE': [ 20, 29],
'HEIGHT': [94, 170],
'WEIGHT': [80, 115]})
# obtaining the list representing the axes of df
print(df.axes)

Explanation

  • Line 1: We import the pandas module.
  • Lines 4–6: We create a dataframe, df.
  • Line 9: We implement the DataFrame.axes attribute to obtain the list representing the axes of df. We print the result to the console.
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources