print the numbers of rows and columns of your dataframe in python

To print the number of rows and columns of a DataFrame in Python using Pandas, you can use the shape attribute.

main.py
import pandas as pd

# create an example dataframe
df = pd.DataFrame({'col1': [1, 2, 3], 'col2': ['a', 'b', 'c']})

# print the number of rows and columns
print('Number of rows:', df.shape[0])
print('Number of columns:', df.shape[1])
234 chars
9 lines

This will output:

main.py
Number of rows: 3
Number of columns: 2
39 chars
3 lines

related categories

gistlibby LogSnag