Python Practice › Pandas Programs › Program 30
First n rows
Write a pandas program to print the first n rows.
Output
n square 0 1 1 1 2 4 2 3 9
Approach
head(n).
Solution
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
Learn the concept
New to this topic? Read the lesson, then come back.