How To Display Only Row and Column Labels Of A DataFrame?


How To Display Only Row and Column Labels Of A DataFrame?

Table Of Contents:

  1. Syntax To Display Only Row and Columns Of Data Frame.
  2. Examples Of Displaying Only Rows and Columns.

(1) Syntax:

pandas.DataFrame.axes

Description:

  • Return a list representing the axes of the DataFrame.

  • It has the row axis labels and column axis labels as the only members. They are returned in that order.

(2) Examples Of Displaying Rows and Columns :

Example-1

import pandas as pd
student = {'Name':['Subrat','Abhispa','Arpita','Anuradha','Namita'],
          'Roll_No':[100,101,102,103,104],
          'Subject':['Math','English','Science','History','Commerce'],
          'Mark':[95,88,76,73,93]}
student_object = pd.DataFrame(student)
student_object

Output:

student_object.axes

Output:

[RangeIndex(start=0, stop=5, step=1),
 Index(['Name', 'Roll_No', 'Subject', 'Mark'], dtype='object')]

Example-2

import pandas as pd
path = "E:\Blogs\Pandas\Documents\Mall_Customers.csv"
customer_details = pd.read_csv(path)
customer_details

Output:

customer_details.axes

Output:

[RangeIndex(start=0, stop=200, step=1),
 Index(['CustomerID', 'Genre', 'Age', 'Annual_Income_(k$)', 'Spending_Score',
        'date'],
       dtype='object')]

Leave a Reply

Your email address will not be published. Required fields are marked *