Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Get Size of the Pandas DataFrame

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

In this article, we will discuss how to get the size of the Pandas Dataframe using Python.

Method 1 : Using df.size

This will return the size of dataframe  i.e. rows*columns

Syntax:

dataframe.size

where, dataframe is the input dataframe

Example: Python code to create a student dataframe and display size

Python3




# import pandas module
import pandas as pd
  
# create a dataframe
# with 5 rows and 3 columns
data = pd.DataFrame({
    'name': ['sravan', 'ojsawi', 'bobby', 'rohith', 'gnanesh'],
    'subjects': ['java', 'php', 'html/css', 'python', 'R'],
    'marks': [98, 90, 78, 91, 87]
})
  
# display dataframe
print(data)
  
# get the size
data.size

Output:

Method 2 : Using df.shape

This function will return the number of rows and columns in the dataframe

Syntax:

dataframe.shape

where, dataframe is the input dataframe

Example: Python program to get the shape of the dataframe

Python3




# import pandas module
import pandas as pd
  
# create a dataframe
# with 5 rows and 3 columns
data = pd.DataFrame({
    'name': ['sravan', 'ojsawi', 'bobby', 'rohith', 'gnanesh'],
    'subjects': ['java', 'php', 'html/css', 'python', 'R'],
    'marks': [98, 90, 78, 91, 87]
})
  
# display dataframe
print(data)
  
# get the shape
data.shape

Output:

Method 3: Using df.ndim

This will return the number of dimensions present in the dataframe.

Syntax:

data.ndim

where, dataframe is the input dataframe

Example: Python program to get the dimension of the dataframe

Python3




# import pandas module
import pandas as pd
  
# create a dataframe
# with 5 rows and 3 columns
data = pd.DataFrame({
    'name': ['sravan', 'ojsawi', 'bobby', 'rohith', 'gnanesh'],
    'subjects': ['java', 'php', 'html/css', 'python', 'R'],
    'marks': [98, 90, 78, 91, 87]
})
  
# display dataframe
print(data)
  
# get the dimensions
data.ndim

Output:


My Personal Notes arrow_drop_up
Last Updated : 28 Nov, 2021
Like Article
Save Article
Similar Reads
Related Tutorials