Number of Rows, Columns & Dimensions of pandas DataFrame in Python (3 Examples)
On this page you’ll learn how to count number of Rows & Columns of a pandas DataFrame in Python programming.
Setting up the Examples
import pandas as pd # Load pandas library |
import pandas as pd # Load pandas library
my_df = pd.DataFrame({'A':range(1, 5), # Constructing data 'B':range(5, 1, - 1), 'C':range(6, 10)}) print(my_df) # Displaying example data # A B C # 0 1 5 6 # 1 2 4 7 # 2 3 3 8 # 3 4 2 9 |
my_df = pd.DataFrame({'A':range(1, 5), # Constructing data 'B':range(5, 1, - 1), 'C':range(6, 10)}) print(my_df) # Displaying example data # A B C # 0 1 5 6 # 1 2 4 7 # 2 3 3 8 # 3 4 2 9
Example 1: Returning the Number of Rows of a pandas DataFrame
print(my_df.shape[0]) # Using shape attribute # 4 |
print(my_df.shape[0]) # Using shape attribute # 4
Example 2: Returning the Number of Variables of a pandas DataFrame
print(my_df.shape[1]) # Using shape attribute # 3 |
print(my_df.shape[1]) # Using shape attribute # 3
Example 3: Returning the Dimensions of a pandas DataFrame
print(my_df.shape) # Using shape attribute # (4, 3) |
print(my_df.shape) # Using shape attribute # (4, 3)