For a dataframe df, one can use any of the following:

  • len(df.index)
  • df.shape[0]
  • df[df.columns[0]].count() (== number of non-NaN values in first column)


Code to reproduce the plot:

import numpy as np
import pandas as pd
import perfplot

perfplot.save(
    "out.png",
    setup=lambda n: pd.DataFrame(np.arange(n * 3).reshape(n, 3)),
    n_range=[2**k for k in range(25)],
    kernels=[
        lambda df: len(df.index),
        lambda df: df.shape[0],
        lambda df: df[df.columns[0]].count(),
    ],
    labels=["len(df.index)", "df.shape[0]", "df[df.columns[0]].count()"],
    xlabel="Number of rows",
)
Answer from root on Stack Overflow
Discussions

How to find the number of rows and columns in a Pandas dataframe? - Python - Data Science Dojo Discussions
We can find the number of rows and columns in a Pandas Dataframe using 3 different methods: 1. Using df.info() method The info() method of a Pandas DataFrame displays information about the data frame, including the data types of the columns, the number of non-null values in each column, and ... More on discuss.datasciencedojo.com
🌐 discuss.datasciencedojo.com
1
0
November 29, 2022
How to count the number of rows and columns in a .csv file without using pandas
You use the CSV library. Which btw is what pandas uses when it reads in CSV files. Or if you can’t use the CSV library either, you can read the file in line by line, split each line on comas and the the length of the list from each split. More on reddit.com
🌐 r/pythonhelp
3
2
February 1, 2023
[HELP] How do I get the maximum number of columns with data in a specific row?
Firstly you will want to read the Excel using pandas. How to read Excel file using Pandas . Once you have read the file you will get a pandas dataframe that will act as a table that represents your data. Then to get the number of columns you would use “len(dataframe.columns)” to get number of columns in a given row. Example of getting the number of columns . Hopefully this answers question, but feel free to ask clarifying questions. More on reddit.com
🌐 r/learnpython
4
1
June 26, 2021
How to sum rows and columns in a 2d list?

If you want to do this without numpy:

sum_rows = [sum(x) for x in values]
sum_cols = [sum(x) for x in zip(*values)]

For larger arrays, numpy.sum is the way to go.

More on reddit.com
🌐 r/learnpython
3
4
April 18, 2016
🌐
Board Infinity
boardinfinity.com › blog › pandas-count-rows
Count Rows and Column with Pandas | Board Infinity
January 2, 2025 - The use of this method can be useful ... to count the total number of rows in dataframe with non-null values you can use .count() on the whole DataFrame....
🌐
w3resource
w3resource.com › python-exercises › pandas › python-pandas-data-frame-exercise-8.php
Pandas DataFrame: Count the number of rows and columns of a DataFrame - w3resource
September 5, 2025 - Write a Pandas program to count rows and columns, then verify that the product equals the total number of elements in the DataFrame.
🌐
Note.nkmk.me
note.nkmk.me › home › python › pandas
pandas: Get the number of rows, columns, elements (size) in DataFrame | note.nkmk.me
May 4, 2025 - The total number of elements in a DataFrame is available via the size attribute, which equals row_count * column_count. pandas.DataFrame.size — pandas 2.2.3 documentation · print(df.size) # 10692 print(df.shape[0] * df.shape[1]) # 10692 ...
🌐
GeeksforGeeks
geeksforgeeks.org › get-the-number-of-rows-and-number-of-columns-in-pandas-dataframe
Get the number of rows and number of columns in Pandas Dataframe - GeeksforGeeks
July 2, 2020 - # import pandas library import pandas as pd # dictionary with list object in values details = { 'Name' : ['Ankit', 'Aishwarya', 'Shaurya', 'Shivangi'], 'Age' : [23, 21, 22, 21], 'University' : ['BHU', 'JNU', 'DU', 'BHU'], } # creating a Dataframe object df = pd.DataFrame(details, columns = ['Name', 'Age', 'University'], index = ['a', 'b', 'c', 'd']) # Get the number of Rows and columns df.shape Output: ... Python Tutorial – Python is one of the most popular programming languages.
🌐
Learning About Electronics
learningaboutelectronics.com › Articles › How-to-find-the-number-of-rows-and-columns-in-an-array-in-Python.php
How to Find the Number of Rows and Columns in an Array in Python
We do this using the reshape() function. We reshape this one-dimensional array into a two-dimensional array that has 5 rows and 6 columns. We then check the structure of the array using the statement, array1.shape ... This tells us that the array has 5 rows and 6 columns.
Find elsewhere
🌐
freeCodeCamp
freecodecamp.org › news › pandas-count-rows-how-to-get-the-number-of-rows-in-a-dataframe
Pandas Count Rows – How to Get the Number of Rows in a Dataframe
May 19, 2023 - The first value, 3, is the number of rows in the dataframe while the second value, 2, is the number of columns.
🌐
Data Science Dojo
discuss.datasciencedojo.com › python
How to find the number of rows and columns in a Pandas dataframe? - Python - Data Science Dojo Discussions
November 29, 2022 - We can find the number of rows and columns in a Pandas Dataframe using 3 different methods: 1. Using df.info() method The info() method of a Pandas DataFrame displays information about the data frame, including the dat…
🌐
AskPython
askpython.com › home › count the rows and columns in a pandas dataframe [step-by-step]
Count the Rows and Columns in a Pandas Dataframe [Step-By-Step] - AskPython
February 16, 2023 - Similar to the above examples, here, the index keyword is used for getting the number of rows, and the column keyword is used to get the number of columns.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.count.html
pandas.DataFrame.count — pandas 3.0.2 documentation
Count unique combinations of columns. ... Number of DataFrame rows and columns (including NA elements).
🌐
Saturn Cloud
saturncloud.io › blog › 5-easy-ways-to-get-pandas-dataframe-row-count
5 Easy Ways to Get Pandas DataFrame Row Count | Saturn Cloud Blog
December 8, 2023 - You won’t get additional details about the DataFrame’s structure or data types. Another way to get the row count of a Pandas DataFrame is to use the shape attribute, which returns a tuple of the number of rows and columns in the DataFrame.
🌐
Javatpoint
javatpoint.com › how-to-get-the-number-of-rows-and-columns-in-dataframe-python
How to Get the Number of Rows and Columns in Dataframe Python - Javatpoint
How to Get the Number of Rows and Columns in Dataframe Python with tutorial, tkinter, button, overview, canvas, frame, environment set-up, first python program, etc.
🌐
DEV Community
dev.to › askyt › pandas-count-rows-how-to-get-the-number-of-rows-in-a-dataframe-3ll7
Pandas Count Rows – How to Get the Number of Rows in a Dataframe - DEV Community
March 31, 2024 - Both df.axes[0].size and len(df.axes[0]) return the number of rows in df. Print the number of rows. ... In cases where you might be interested in the count of non-missing (non-NaN) values in a specific column, you can use the .count() method ...
🌐
w3resource
w3resource.com › python-exercises › numpy › basic › numpy-basic-exercise-26.php
NumPy: Find the number of rows and columns of a given matrix - w3resource
August 28, 2025 - Determine the shape of a given matrix and print the number of rows. Extract and print the number of columns from a randomly generated 2D array.
🌐
MLJAR
mljar.com › blog › pandas-dataframe-row-count
3 ways to get Pandas DataFrame row count
November 12, 2022 - The simplest approach to get row count is to use df.shape. It returns the touple with a number of rows and columns:
🌐
YouTube
youtube.com › watch
Count Number of Rows & Columns of pandas DataFrame in ...
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.