Preview trailing rows
Quickly inspect the newest or final records in a DataFrame.
Polars · Module
Returns the last n rows of a DataFrame. The default is five rows; negative n returns all rows except the first abs(n) rows.
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.
DataFrame.tail(*n: int = 5*) → DataFrame| Name | Type | Description |
|---|---|---|
n | int = 5 | Number of rows to return. A negative value returns all rows except the first abs(n). |
DataFrame containing the selected ending rows, or the rows remaining after excluding the first abs(n) rows when n is negative.
n rows.n, defaults that argument to 5, and returns a DataFrame.n parameter controls how many rows the ordinary positive-count operation returns.n does not count backward from the end; it excludes the first abs(n) rows and returns everything after them.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.
Quickly inspect the newest or final records in a DataFrame.
Exclude an initial block while retaining the rest of a table.
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.
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.
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.
headslice