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

Pandas · Module

df.tail

Returns the last rows of a DataFrame by positional order. It selects five rows by default and supports positive or negative values of n.

How it works

Call DataFrame.tail to obtain rows from the end of a DataFrame by positional order. The default selects five rows; a positive integer selects that many, while a negative integer omits that many rows from the beginning.

Syntax

DataFrame.tail(*n=5*)

Parameters

NameTypeDescription
nint, default 5Number of rows to select.

Returns

The last n rows of the caller object.

Key points

  • The method selects rows at the end of the DataFrame.
  • Selection is positional, so the method examines row order rather than filtering by column values.
  • Use it as a compact inspection step after transformations that may change row order or contents.
  • n is an integer and defaults to five when omitted.
  • For a nonnegative value, n controls the number of rows returned.

Common mistakes

  • A negative value does not mean “take the last |n| rows”; it excludes that many rows from the front.
  • Requesting more rows than exist returns the complete DataFrame rather than raising an error.

Example: Select the final rows

import pandas as pd

df = pd.DataFrame({"animal": ["alligator", "bee", "falcon", "lion", "monkey"]})
print(df.tail(2))

Prints the final two rows of the DataFrame.

When to use it

Quick data inspection

Inspect the final records of a loaded or transformed table.

Verify sorted output

Confirm the resulting order after sorting.

Inspect appended rows

Check newly appended records at the end of a table.

Interview questions

QWhat does DataFrame.tail return?

It returns the final n rows according to positional order. With no argument, n defaults to 5.

Follow-up: What does tail(-3) do? It returns every row except the first three, equivalent to positional slicing with df[3:].

QWhat is the n parameter and what happens when it is too large?

The argument is an integer specifying how many rows to select, and its default is 5. The method returns the last n rows of the caller object.

Follow-up: What happens when the requested count exceeds the row count? The method returns all available rows.

QHow does negative n differ from positive n?

A positive n selects rows from the end. A negative n instead removes the first |n| rows, so tail(-3) is equivalent to df[3:].

Follow-up: Why is this useful in practice? It provides a quick positional check after operations such as sorting or appending rows.

  • DataFrame.head

Source: pandas.DataFrame.tail. Checked 2026-10-15.