How To Get The Shape Of A DataFrame?


How To Get The Shape Of A DataFrame?

Table Of Contents:

  1. Syntax To Get Shape Of Data Frame.
  2. Examples Of Getting Shape.

(1) Syntax:

pandas.DataFrame.shape

Description:

  • Return a tuple representing the dimensionality of the DataFrame.

(2) Examples Of 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.shape

Output:

(5, 4)

Note:

  • ‘5’ Represents the number of rows of a DataFrame.
  • ‘4’ Represents the number of columns of the DataFrame.

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.shape

Output:

(200, 6)

Note:

  • ‘200’ Represents the number of rows of a DataFrame.
  • ‘6’ Represents the number of columns of the DataFrame.

Leave a Reply

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