Count the number of rows and columns of Pandas dataframe
In this article, we’ll see how we can get the count of the total number of rows and columns in a Pandas DataFrame. There are different methods by which we can do this. Let’s see all these methods with the help of examples.
Example 1: We can use the
dataframe.shape to get the count of rows and columns.
dataframe.shape gives count of rows and columns respectively.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
Example 2 : We can use the
len() method to get the count of rows and columns.
dataframe.axes represents rows and
dataframe.axes represents columns. So,
dataframe.axes gives the count of rows and columns respectively.
Example 3 : Similar to the example 2,
dataframe.index represents rows and
dataframe.columns represents columns. So,
len(dataframe.columns) gives count of rows and columns respectively.