How to Get the Row Size of DataFrame using Pandas Library in Jupyter Notebook

Posted on

Introduction

This article will show the way to get the row size of a DataFrame using Pandas library. The execution of the process is running in the Jupyter Notebook. So, the first step is to run the Jupyter Notebook. The following is the execution process of Jupyter Notebook via Command Line :

(myenv) C:\python\data-science>jupyter notebook
[I 17:08:28.062 NotebookApp] Serving notebooks from local directory: C:\python\data-science
[I 17:08:28.062 NotebookApp] The Jupyter Notebook is running at:
[I 17:08:28.067 NotebookApp] http://localhost:8888/?token=4dd9801ef2aacad1d445955b0ae4621b4c669da84c617e7b
[I 17:08:28.068 NotebookApp]  or http://127.0.0.1:8888/?token=4dd9801ef2aacad1d445955b0ae4621b4c669da84c617e7b
[I 17:08:28.070 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 17:08:28.225 NotebookApp]

    To access the notebook, open this file in a browser:
        file:///C:/Users/Personal/AppData/Roaming/jupyter/runtime/nbserver-8796-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=4dd9801ef2aacad1d445955b0ae4621b4c669da84c617e7b
     or http://127.0.0.1:8888/?token=4dd9801ef2aacad1d445955b0ae4621b4c669da84c617e7b

Get the Row Size of DataFrame using Pandas Library in Jupyter Notebook

Don’t forget to load the data either create it manually or import it from another source. For an example, this link is an article where the title of it is ‘How to Read CSV File into a DataFrame using Pandas Library in Jupyter Notebook’. It is a good example as a reference to load the data from a CSV file. In this context, it will use the example on that article. So, after successfully load the data, just execute the following command to count the row available in the DataFrame :

 

import pandas as pd

data = pd.read_csv("transactions1.csv",sep=";",low_memory=False)
len(data.index)

Another command for displaying or counting the row available in the DataFrame is also by using the shape attribute as follows :

data.shape[0]

The shape attribute contains an array of two elements. The first index is indicating the row size. The above output will be exist as follows :

How to Get the Row Size of DataFrame using Pandas Library in Jupyter Notebook
How to Get the Row Size of DataFrame using Pandas Library in Jupyter Notebook

As in the above image, the row of the DataFrame using either the len(data.index) command and also the data.shape[0] command will give the same output. The result of the command is ‘641914’. As for displaying the size of the column of a DataFrame, just access this link. It is an article with the title of ‘How to Get the Column Size of DataFrame using Pandas Library in Jupyter Notebook’ where it is showing how to display the size of the column of a DataFrame.

One thought on “How to Get the Row Size of DataFrame using Pandas Library in Jupyter Notebook

Leave a Reply