Python Practice › Pandas Programs › Program 35

Count rows and columns

EasyPandas Programs · 35 of 95

Write a pandas program to count the rows and columns.

Advertisement
Output
No of rows: 4
No of columns: 2

Approach

  1. shape.

Solution

Python
import pandas as pddf = pd.DataFrame({"name": ["Alex", "John", "Peter", "Klaus"], "age": [30, 27, 29, 33]})rows, cols = df.shapeprint("No of rows:", rows)print("No of columns:", cols)
Output
No of rows: 4
No of columns: 2
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More pandas programs

← All 95 Pandas Programs