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 dataframedf = pd.DataFrame({'AGE': [ 20, 29],'HEIGHT': [94, 170],'WEIGHT': [80, 115]})# obtaining the list representing the axes of dfprint(df.axes)
Explanation
- Line 1: We import the
pandasmodule. - Lines 4–6: We create a dataframe,
df. - Line 9: We implement the
DataFrame.axesattribute to obtain the list representing the axes ofdf. We print the result to the console.