df.shape, where df is your DataFrame.

Answer from BrenBarn on Stack Overflow
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.size.html
pandas.DataFrame.size — pandas 3.0.2 documentation
Return an int representing the number of elements in this object · Return the number of rows if Series. Otherwise return the number of rows times number of columns if DataFrame
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-pandas-df-size-df-shape-and-df-ndim
Pandas df.size, df.shape and df.ndim Methods - GeeksforGeeks
July 11, 2025 - df.size is used to return the total number of elements in a DataFrame or Series. If we're working with a DataFrame it gives the product of rows and columns or if we're working with a Series it just returns the number of elements (rows).
🌐
DataCamp
datacamp.com › tutorial › python-dataframe-size
Finding the Size of a DataFrame in Python | DataCamp
February 14, 2024 - You can learn more about DataFrames in DataCamp’s data manipulation with pandas course or this Python pandas tutorial. Python pandas is a library that allows analysts to easily work with DataFrames. This library has a straightforward shape method used to find the size of a DataFrame. import pandas as pd # Creating a sample DataFrame df = pd.DataFrame({'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [25, 30, 22], 'City': ['New York', 'San Francisco', 'Los Angeles']}) # Using shape to get the size rows, columns = df.shape print(f"Number of rows: {rows}, Number of columns: {columns}")
🌐
W3Schools
w3schools.com › python › pandas › ref_df_size.asp
Pandas DataFrame size Property
Pandas HOME Pandas Intro Pandas ... Wrong Format Cleaning Wrong Data Removing Duplicates ... The size property returns the number of elements in the DataFrame....
🌐
Pandas
pandas.pydata.org › pandas-docs › stable › reference › api › pandas.DataFrame.size.html
pandas.DataFrame.size — pandas 3.0.1 documentation
Return an int representing the number of elements in this object · Return the number of rows if Series. Otherwise return the number of rows times number of columns if 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 - Modified: 2025-05-04 | Tags: Python, pandas · This article explains how to get the number of rows, columns, and total elements (i.e., size) in a pandas.DataFrame and pandas.Series. Contents · Get the number of rows, columns, and elements in a pandas.DataFrame · Display the number of rows and columns: df.info() Get the number of rows and columns: df.shape ·
Top answer
1 of 2
188

df.shape, where df is your DataFrame.

2 of 2
45

Summary of all ways to get info on dimensions of DataFrame or Series

There are a number of ways to get information on the attributes of your DataFrame or Series.

Create Sample DataFrame and Series

df = pd.DataFrame({'a':[5, 2, np.nan], 'b':[ 9, 2, 4]})
df

     a  b
0  5.0  9
1  2.0  2
2  NaN  4

s = df['a']
s

0    5.0
1    2.0
2    NaN
Name: a, dtype: float64

shape Attribute

The shape attribute returns a two-item tuple of the number of rows and the number of columns in the DataFrame. For a Series, it returns a one-item tuple.

df.shape
(3, 2)

s.shape
(3,)

len function

To get the number of rows of a DataFrame or get the length of a Series, use the len function. An integer will be returned.

len(df)
3

len(s)
3

size attribute

To get the total number of elements in the DataFrame or Series, use the size attribute. For DataFrames, this is the product of the number of rows and the number of columns. For a Series, this will be equivalent to the len function:

df.size
6

s.size
3

ndim attribute

The ndim attribute returns the number of dimensions of your DataFrame or Series. It will always be 2 for DataFrames and 1 for Series:

df.ndim
2

s.ndim
1

The tricky count method

The count method can be used to return the number of non-missing values for each column/row of the DataFrame. This can be very confusing, because most people normally think of count as just the length of each row, which it is not. When called on a DataFrame, a Series is returned with the column names in the index and the number of non-missing values as the values.

df.count() # by default, get the count of each column

a    2
b    3
dtype: int64


df.count(axis='columns') # change direction to get count of each row

0    2
1    2
2    1
dtype: int64

For a Series, there is only one axis for computation and so it just returns a scalar:

s.count()
2

Use the info method for retrieving metadata

The info method returns the number of non-missing values and data types of each column

df.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 3 entries, 0 to 2
Data columns (total 2 columns):
a    2 non-null float64
b    3 non-null int64
dtypes: float64(1), int64(1)
memory usage: 128.0 bytes
🌐
Delft Stack
delftstack.com › home › howto › python pandas › python pandas df size df shape and df ndim
How to Pandas DataFrame Dimensions | Delft Stack
February 2, 2024 - In the following example, we imported or read a .csv file using pd.csvread() and created a DataFrame. Using the Pandas property dataframe.size, we displayed the size of the given DataFrame.
Find elsewhere
🌐
w3resource
w3resource.com › pandas › dataframe › dataframe-size.php
Pandas DataFrame property: size - w3resource
August 19, 2022 - Pandas DataFrame - size property: The size property is used to return an int representing the number of elements in this object.
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › how to get size of pandas dataframe?
How to Get Size of Pandas DataFrame? - Spark By {Examples}
June 23, 2025 - You can get the size of a Pandas DataFrame using the DataFrame.size attribute. This attribute returns the number of elements in the DataFrame, which is
🌐
GeeksforGeeks
geeksforgeeks.org › python › get-size-of-the-pandas-dataframe
Get Size of the Pandas DataFrame - GeeksforGeeks
July 23, 2025 - # 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 ... # 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 ... This will return the number of dimensions present in the dataframe.
🌐
Apache
spark.apache.org › docs › latest › api › python › reference › pyspark.pandas › api › pyspark.pandas.DataFrame.size.html
pyspark.pandas.DataFrame.size — PySpark 4.1.1 documentation
Return an int representing the number of elements in this object. Return the number of rows if Series. Otherwise return the number of rows times number of columns if DataFrame. Examples · >>> s = ps.Series({'a': 1, 'b': 2, 'c': None}) >>> s.size 3 · >>> df = ps.DataFrame({'col1': [1, 2, None], ...
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 2.1 › reference › api › pandas.DataFrame.size.html
pandas.DataFrame.size — pandas 2.1.4 documentation
Return an int representing the number of elements in this object · Return the number of rows if Series. Otherwise return the number of rows times number of columns if DataFrame
🌐
Python Examples
pythonexamples.org › pandas-dataframe-shape
Pandas DataFrame.shape
Learn how to use pandas DataFrame.shape to retrieve the dimensions of a DataFrame. Includes examples for dynamic operations, empty DataFrames, and filtering.
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 0.25.3 › reference › api › pandas.DataFrame.size.html
pandas.DataFrame.size — pandas 0.25.3 documentation
Number of elements in the array. Examples · >>> s = pd.Series({'a': 1, 'b': 2, 'c': 3}) >>> s.size 3 · >>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]}) >>> df.size 4 · index · modules | next | previous | pandas 0.25.3 documentation » · API reference » ·
🌐
DataScience Made Simple
datasciencemadesimple.com › home › size and shape of a dataframe in pandas python
Size and shape of a dataframe in pandas python - DataScience Made Simple
November 15, 2019 - Size of a dataframe is the number of fields in the dataframe is number of rows * number of columns. size and Shape of a dataframe in pandas python.
🌐
Pandas
pandas.pydata.org › docs › dev › reference › api › pandas.DataFrame.size.html
pandas.DataFrame.size — pandas ain documentation
Return an int representing the number of elements in this object · Return the number of rows if Series. Otherwise return the number of rows times number of columns if DataFrame
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.shape.html
pandas.DataFrame.shape — pandas 3.0.2 documentation
Unlike the len() method, which only returns the number of rows, shape provides both row and column counts, making it a more informative method for understanding dataset size. See also · numpy.ndarray.shape · Tuple of array dimensions. Examples · >>> df = pd.DataFrame({"col1": [1, 2], "col2": [3, 4]}) >>> df.shape (2, 2) >>> df = pd.DataFrame({"col1": [1, 2], "col2": [3, 4], "col3": [5, 6]}) >>> df.shape (2, 3) On this page