Count the number of rows and columns of Pandas dataframe Last Updated : 01 Aug, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report 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[0] and dataframe.shape[1] gives count of rows and columns respectively. Python3 1== # importing the module import pandas as pd # creating a DataFrame dict = {'Name' : ['Martha', 'Tim', 'Rob', 'Georgia'], 'Marks' : [87, 91, 97, 95]} df = pd.DataFrame(dict) # displaying the DataFrame display(df) # fetching the number of rows and columns rows = df.shape[0] cols = df.shape[1] # displaying the number of rows and columns print("Rows: " + str(rows)) print("Columns: " + str(cols)) Output : Example 2 : We can use the len() method to get the count of rows and columns. dataframe.axes[0] represents rows and dataframe.axes[1] represents columns. So, dataframe.axes[0] and dataframe.axes[1] gives the count of rows and columns respectively. Python3 1== # importing the module import pandas as pd # creating a DataFrame dict = {'Name':['Martha', 'Tim', 'Rob', 'Georgia'], 'Marks':[87, 91, 97, 95]} df = pd.DataFrame(dict) # displaying the DataFrame display(df) # fetching the number of rows and columns rows = len(df.axes[0]) cols = len(df.axes[1]) # displaying the number of rows and columns print("Rows: " + str(rows)) print("Columns: " + str(cols)) Output : Example 3 : Similar to the example 2, dataframe.index represents rows and dataframe.columns represents columns. So, len(dataframe.index) and len(dataframe.columns) gives count of rows and columns respectively. Python3 1== # importing the module import pandas as pd # creating a DataFrame dict = {'Name':['Martha', 'Tim', 'Rob', 'Georgia'], 'Marks':[87, 91, 97, 95]} df = pd.DataFrame(dict) # displaying the DataFrame display(df) # fetching the number of rows and columns rows = len(df.index) cols = len(df.columns) # displaying the number of rows and columns print("Rows: " + str(rows)) print("Columns: " + str(cols)) Output : Comment More infoAdvertise with us Next Article Count number of columns of a Pandas DataFrame P parasmadan15 Follow Improve Article Tags : Python Practice Tags : python Similar Reads Count number of rows and columns in Pandas dataframe In Pandas understanding number of rows and columns in a DataFrame is important for knowing structure of our dataset. Whether we're cleaning the data, performing calculations or visualizing results finding shape of the DataFrame is one of the initial steps. In this article, we'll explore various ways 3 min read Count number of columns of a Pandas DataFrame Let's discuss how to count the number of columns of a Pandas DataFrame. Lets first make a dataframe. Example: Python3 # Import Required Libraries import pandas as pd import numpy as np # Create a dictionary for the dataframe dict = {'Name': ['Sukritin', 'Sumit Tyagi', 'Akriti Goel', 'Sanskriti', 'Ab 2 min read Get the number of rows and number of columns in Pandas Dataframe Pandas provide data analysts a variety of pre-defined functions to Get the number of rows and columns in a data frame. In this article, we will learn about the syntax and implementation of few such functions. Method 1: Using df.axes() Method axes() method in pandas allows to get the number of rows a 3 min read Get number of rows and columns of PySpark dataframe In this article, we will discuss how to get the number of rows and the number of columns of a PySpark dataframe. For finding the number of rows and number of columns we will use count() and columns() with len() function respectively. df.count(): This function is used to extract number of rows from t 6 min read How to Count Distinct Values of a Pandas Dataframe Column? Let's discuss how to count distinct values of a Pandas DataFrame column. Using pandas.unique()You can use pd.unique()to get all unique values in a column. To count them, apply len()to the result. This method is useful when you want distinct values and their count.Pythonimport pandas as pd # Create D 4 min read Count Frequency of Columns in Pandas DataFrame When working with data in Pandas counting how often each value appears in a column is one of the first steps to explore our dataset. This helps you understand distribution of data and identify patterns. Now weâll explore various ways to calculate frequency counts for a column in a Pandas DataFrame.1 2 min read Like