Quick data inspection
Inspect the final records of a loaded or transformed table.
Pandas · Module
Returns the last rows of a DataFrame by positional order. It selects five rows by default and supports positive or negative values of n.
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.
DataFrame.tail(*n=5*)| Name | Type | Description |
|---|---|---|
n | int, default 5 | Number of rows to select. |
The last n rows of the caller object.
n is an integer and defaults to five when omitted.n controls the number of rows returned.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.
Inspect the final records of a loaded or transformed table.
Confirm the resulting order after sorting.
Check newly appended records at the end of a table.
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:].
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.
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