Python Practice › Pandas Programs › Program 31
Last n rows
Write a pandas program to print the last n rows.
Output
n square 8 9 81 9 10 100
Approach
tail(n).
Solution
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
Learn the concept
New to this topic? Read the lesson, then come back.