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 OverflowGeeksforGeeks
geeksforgeeks.org › python › count-the-number-of-rows-and-columns-of-a-pandas-dataframe
Count number of rows and columns in Pandas dataframe - GeeksforGeeks
July 15, 2025 - In above example, df.shape returns (3, 3) which means it has 3 rows and 3 columns.
Top answer 1 of 16
3013
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",
)
2 of 16
501
Suppose df is your dataframe then:
count_row = df.shape[0] # Gives number of rows
count_col = df.shape[1] # Gives number of columns
Or, more succinctly,
r, c = df.shape
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
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
[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
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.
Videos
00:16
Check the number. of rows and columns in a DataFrame #python #pandas ...
04:07
#203 Python Excel Course Count Number of Rows and Columns - YouTube
04:48
Finding number of rows and number of columns of Table using Selenium ...
04:41
How To Count The no of Rows and Columns In a CSV File - YouTube
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.
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.
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).
Okpedia
how.okpedia.org › en › python › how-to-find-the-number-of-rows-and-columns-of-a-matrix-in-python
[Python] How to find the number of rows and columns of a matrix - Okpedia
To find out the number of rows and columns of a matrix in Python use the function shape of NumPy.
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.
Reddit
reddit.com › r/pythonhelp › how to count the number of rows and columns in a .csv file without using pandas
r/pythonhelp on Reddit: How to count the number of rows and columns in a .csv file without using pandas
February 1, 2023 -
Hello y’all! I’m fairly new to Python and I’m confused as to how you can count the number of rows and columns in a .csv dataset WITHOUT using any functions from the pandas library. Any help will be appreciated.
Top answer 1 of 2
2
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.
2 of 2
1
Load the file using the built-in csv module. import csv with open('filename.csv') as f: data = list(csv.reader(f)) print("rows:", len(data)) print("columns:", len(data[0]))