Get the number of rows and number of columns in pandas dataframe python

In this tutorial we will learn how to get the number of rows and number of columns in  pandas dataframe python.

Create dataframe :

import pandas as pd
import numpy as np

#Create a DataFrame
d = {
    'Name':['Alisa','Bobby','Cathrine','Alisa','Bobby','Cathrine',
            'Alisa','Bobby','Cathrine','Alisa','Bobby','Cathrine'],
    'Exam':['Semester 1','Semester 1','Semester1','Semester1','Semester1','Semester 1',
            'Semester 2','Semester 2','Semester2','Semester2','Semester2','Semester 2'],

    'Subject':['Mathematics','Mathematics','Mathematics','Science','Science','Science',
               'Mathematics','Mathematics','Mathematics','Science','Science','Science'],
   'Score':[62,47,55,74,31,77,85,63,42,67,89,81]}

df = pd.DataFrame(d,columns=['Name','Exam','Subject','Score'])
print(df)

so the resultant dataframe will be

Get the number of rows and number of columns in pandas dataframe python 1

 

Get the number of rows and columns of the dataframe in pandas python:

df.shape

we can use dataframe.shape to get the number of rows and number of columns of a dataframe in pandas

So the result will be

(12, 4)

 

 

Get the number of rows of the dataframe in pandas python:

len(df.rows)

so the result will be

12

 

 

Get the number of columns of the dataframe in pandas python:

len(df.columns)

so the result will be

4

 

Get the number of rows and number of columns in pandas dataframe python                                                                                                                Get the number of rows and number of columns in pandas dataframe python