How to find the number of rows and columns in a Pandas dataframe?

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 the memory usage of the data frame.

Example

2. Using len() method

In Pandas, the len() function returns the length of a DataFrame, which is the number of rows in the DataFrame.

Example

3. Using df.shape() method

In Pandas, the shape attribute of a DataFrame returns a tuple that represents the dimensions of the DataFrame. The first element of the tuple is the number of rows, and the second element is the number of columns.

Example