# Expressions and contexts
source: https://docs.chalk.ai/docs/chalkdf/concepts/expressions

## Use the same column expression to derive values, filter rows, and summarize groups.

An expression describes a calculation on the input columns. Import `_` from `chalk` to refer to the current row's columns. You can assign an expression to a Python variable and use it wherever the input has those columns.

```python
from chalk import _
from chalkdf import DataFrame

tx = DataFrame({"user": ["a", "a", "b"], "amount": [12, 8, 30]})

amount = _.amount
with_fee = tx.with_columns((amount + 2).alias("charged"))
eligible = with_fee.filter(_.charged >= 12)
eligible.project({"customer": _.user, "charge": _.charged}).run()
```

| customer · `string` | charge · `int64` |
| ------------------- | ---------------- |
| a                   | 14               |
| b                   | 32               |

Here [`with_columns`](/dataframe-docs#DataFrame.with_columns) keeps the original columns and adds `charged`. The predicate passed to [`filter`](/dataframe-docs#DataFrame.filter) chooses rows. The mapping passed to [`project`](/dataframe-docs#DataFrame.project) defines every output column. For existing columns that already have the right names, use [`select("user", "amount")`](/dataframe-docs#DataFrame.select).

In an aggregation, the same input column contributes multiple values to each result. For example, [`tx.agg(["user"], amount.sum().alias("total"))`](/dataframe-docs#DataFrame.agg) produces one total per user. See [Aggregations](/docs/chalkdf/expressions/aggregations).

### Apply a calculation to several named columns

Build a projection from column names when several fields need the same calculation. The Python comprehension constructs one expression per column before the plan runs.

```python
balances = DataFrame({"cash_cents": [125, 300], "credit_cents": [500, 800]})
amounts = {
    name.removesuffix("_cents") + "_dollars": balances.col(name) / 100.0
    for name in balances.column_names if name.endswith("_cents")
}
balances.project(amounts).run()
```

| cash_dollars · `double` | credit_dollars · `double` |
| ----------------------- | ------------------------- |
| 1.25                    | 5.0                       |
| 3.0                     | 8.0                       |

Each matching column becomes a separate output with its own name. Explicit names make the projected schema visible to the next operation.

See [`DataFrame.with_columns`](/dataframe-docs#DataFrame.with_columns), [`DataFrame.project`](/dataframe-docs#DataFrame.project), [`DataFrame.filter`](/dataframe-docs#DataFrame.filter), [`DataFrame.agg`](/dataframe-docs#DataFrame.agg).





