Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Polars · Module

df.tail

Returns the last n rows of a DataFrame. The default is five rows; negative n returns all rows except the first abs(n) rows.

How it works

Call tail on a DataFrame to obtain its ending rows. The optional count defaults to five; a negative count instead omits that many rows from the beginning and returns the remainder.

Syntax

DataFrame.tail(*n: int = 5*) → DataFrame

Parameters

NameTypeDescription
nint = 5Number of rows to return. A negative value returns all rows except the first abs(n).

Returns

DataFrame containing the selected ending rows, or the rows remaining after excluding the first abs(n) rows when n is negative.

Key points

  • The method selects a suffix of the DataFrame, returning its final n rows.
  • Its documented signature accepts an integer n, defaults that argument to 5, and returns a DataFrame.
  • The n parameter controls how many rows the ordinary positive-count operation returns.
  • A negative count provides a prefix-exclusion form, retaining rows after the excluded leading portion.

Common mistakes

  • A negative n does not count backward from the end; it excludes the first abs(n) rows and returns everything after them.

Example: Get the final rows

import polars as pl

df = pl.DataFrame({"id": [1, 2, 3, 4, 5], "value": [10, 20, 30, 40, 50]})
print(df.tail(2))

Returns a new DataFrame containing the final two rows.

When to use it

Preview trailing rows

Quickly inspect the newest or final records in a DataFrame.

Drop leading rows

Exclude an initial block while retaining the rest of a table.

Interview questions

QWhat does DataFrame.tail do, and what is its default?

DataFrame.tail returns the final n rows as a DataFrame, and n defaults to 5. Passing n=3 therefore selects the last three rows.

Follow-up: What does tail(-3) do? It returns every row except the first three.

QWhat parameter does tail accept and what does it return?

The method accepts n, described as the number of rows to return, and produces a DataFrame. The result preserves the selected rows from the DataFrame's end.

Follow-up: How would you inspect the beginning instead? Use the related head method.

QHow does negative n change the behavior?

A negative argument changes the operation from taking a suffix to dropping a prefix: tail(-3) returns all rows after the first three. This behavior is explicitly documented for negative values.

Follow-up: How can you select a contiguous region more generally? Consider the related slice method.

  • head
  • slice

Source: polars.DataFrame.tail — Polars documentation. Checked 2026-10-15.