Python Practice › Pandas Programs › Program 31

Last n rows

EasyPandas Programs · 31 of 95

Write a pandas program to print the last n rows.

Advertisement
Output
    n  square
8   9      81
9  10     100

Approach

  1. tail(n).

Solution

Python
import pandas as pddf = pd.DataFrame({"n": range(1, 11), "square": [i * i for i in range(1, 11)]})print(df.tail(2))
Output
    n  square
8   9      81
9  10     100
Advertisement

Learn the concept

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

More pandas programs

← All 95 Pandas Programs