Python Practice › Pandas Programs › Program 30

First n rows

EasyPandas Programs · 30 of 95

Write a pandas program to print the first n rows.

Advertisement
Output
   n  square
0  1       1
1  2       4
2  3       9

Approach

  1. head(n).

Solution

Python
import pandas as pddf = pd.DataFrame({"n": range(1, 11), "square": [i * i for i in range(1, 11)]})print(df.head(3))
Output
   n  square
0  1       1
1  2       4
2  3       9
Advertisement

Learn the concept

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

More pandas programs

← All 95 Pandas Programs