# Chalk DataFrames Reference: Row Operations
source: https://docs.chalk.ai/dataframe-docs#section-row-operations

Methods for filtering, ordering, and deduplicating rows.

- `filter` — keep rows matching a boolean expression
- `order_by` — sort rows by one or more columns
- `slice` — select a positional range of rows
- `distinct_on` — deduplicate by a set of key columns

## `filter(expr)`
source: https://docs.chalk.ai/dataframe-docs#DataFrame.filter

Filter rows based on a boolean expression.

**Parameters**

- `expr`: `Expr | Underscore`
  Boolean expression to filter rows. Only rows where the expression evaluates to True are kept.

**Returns**

`DataFrame`

**Examples**

```python
from chalkdf import DataFrame
from chalk.features import _
df = DataFrame.from_dict({"x": [1, 2, 3, 4], "y": [10, 20, 30, 40]})
filtered = df.filter(_.x > 2)
```

## `order_by(columns)`
source: https://docs.chalk.ai/dataframe-docs#DataFrame.order_by

Sort the DataFrame by one or more columns.

**Returns**

`DataFrame`

**Examples**

```python
from chalkdf import DataFrame
df = DataFrame.from_dict({"x": [3, 1, 2], "y": [30, 10, 20]})
# Sort by x ascending
sorted_df = df.order_by("x")
# Sort by x descending, then y ascending
sorted_df = df.order_by(("x", "desc"), "y")
# Sort by x descending, nulls first
sorted_df = df.order_by(("x", "desc", "nulls_first"))
```

## `slice(start, length)`
source: https://docs.chalk.ai/dataframe-docs#DataFrame.slice

Return a subset of rows starting at a specific position.

**Parameters**

- `start`: `int`
  Zero-based index where the slice begins.
- `length`: `int | None` = `None`
  Number of rows to include. If None, includes all remaining rows.

**Returns**

`DataFrame`

**Examples**

```python
from chalkdf import DataFrame
df = DataFrame.from_dict({"x": [1, 2, 3, 4, 5]})
# Get rows 1-3 (indices 1, 2, 3)
sliced = df.slice(1, 3)
```

## `distinct_on(columns)`
source: https://docs.chalk.ai/dataframe-docs#DataFrame.distinct_on

Remove duplicate rows based on the specified partition columns.

For each unique combination of values in `columns`, exactly one row is emitted. Which row is kept within a partition is _not_ guaranteed — the engine may choose any row. If you need a deterministic choice, sort the DataFrame first with `order_by` before calling `distinct_on`.

**Returns**

`DataFrame`

**Raises**

- `ValueError`: If no columns are provided.

**Examples**

```python
from chalkdf import DataFrame
df = DataFrame.from_dict({"x": [1, 1, 2], "y": [10, 20, 30]})
unique = df.distinct_on("x")  # one row per unique x value
```
