Pandas DataFrame Shape Property With Examples

Spread the love

The Pandas DataFrame Shape Property return a tuple representing the number of rows and columns a DataFrame have.

Let’s read a Dataset.

import pandas as pd

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

To know the shape (rows, columns ) of the DataFrame we can write

df.shape
#output
(100, 8)

Since this dataframe has 100 rows and 8 columns we get a tuple (100,8).

To access the number of rows we can write

# get number of rows
df.shape[0]
# output
100

And to access the number of columns we can write

# get number of columns
df.shape[1]
# output
8

Rating: 1 out of 5.

Leave a Reply