get dimensions of pandas df in python

You can get the dimensions of a pandas DataFrame by calling the shape attribute. Here's an example:

main.py
import pandas as pd

# create a sample dataframe
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})

# get the dimensions
print(df.shape) # (3, 2)
148 chars
8 lines

The shape attribute returns a tuple with two elements, the first element is the number of rows and the second element is the number of columns. In this example, the DataFrame has 3 rows and 2 columns, so the shape attribute returns (3, 2).

related categories

gistlibby LogSnag