Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

pandas
data science
dataframe
axes
communitycreator

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

Onyejiaku Theophilus Chidalu

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)
Implementing the DataFrame.axes attribute

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.

RELATED TAGS

pandas
data science
dataframe
axes
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu
RELATED COURSES

View all Courses

Keep Exploring