Show a small leading sample
Previewing a dataset
Polars · Module
DataFrame.limit(n) returns the first n rows as a DataFrame, defaulting to five rows. A negative n returns all rows except the last abs(n) rows.
Call limit on a DataFrame to produce a DataFrame containing a bounded prefix of its rows. A positive n keeps the first n rows, while a negative n removes that many rows from the end instead; the method is equivalent to head.
DataFrame.limit(n: int = 5) -> DataFrame| Name | Type | Description |
|---|---|---|
n | int = 5 | Number of rows to return. Negative values return all rows except the last abs(n) rows. |
DataFrame
limit(n) to keep a leading slice of the DataFrame.limit and head are equivalent DataFrame operations.n argument controls the requested row count.n excludes abs(n) rows from the end.import polars as pl
df = pl.DataFrame({"value": [10, 20, 30, 40, 50]})
print(df.limit(3))
print(df.limit(-2))Returns a new DataFrame containing the first three rows, then all rows except the final two.
Previewing a dataset
Bounding intermediate results
Dropping a known tail
DataFrame.limit return, and what is its default?DataFrame.limit(n) returns the first n rows as a DataFrame, with n defaulting to 5. It is an alias for DataFrame.head().
Follow-up: What does limit(-n) do? It returns every row except the last abs(n) rows.
limit?The method accepts one integer parameter, n, which specifies the number of rows to return. The result preserves the DataFrame form rather than returning a scalar or a list.
Follow-up: How would you inspect the result without changing the original object? Assign or print the returned DataFrame; the documented operation returns a DataFrame.
n differ from positive n?A positive limit selects a prefix of the DataFrame. A negative limit instead returns all rows other than the specified number at the end.
Follow-up: What related API provides the same behavior? DataFrame.head() is the documented alias.
DataFrame.head