Pandas DataFrame Size Property With Examples

Spread the love

The Pandas DataFrame Size Property returns the number of elements in the DataFrame. It returns the number of rows if it is a series, Otherwise return the number of rows times number of columns if DataFrame.

Let’s read a dataset to illustrate it.

import pandas as pd

url = 'https://raw.githubusercontent.com/bprasad26/lwd/master/data/clothing_store_sales.csv'
df = pd.read_csv(url)
df.head()

DataFrame –

When it’s a DataFrame the size property will return the number of rows times the number of columns.

df.size
#output 
800

Since there are 100 rows and 8 columns the size is 800.

Series –

When it is a series then it returns the number of rows in it.

# series
net_sales = df['Net Sales']
net_sales.size
#output
100

Since it is a series and the number of rows are 100 therefore the size is 100.

Rating: 1 out of 5.

Leave a Reply