Style guide · rule 01
Column Access
Name columns, don’t reach into the DataFrame object.
A column referenced as `df.amount` or `df["amount"]` is bound to that one Python variable. The moment you lift the expression into a helper, reuse it against a differently-named DataFrame, or reorder the pipeline, it stops working — and often fails at runtime rather than at review time. `F.col("amount")` and plain string references describe the column by name and carry no attachment to any particular DataFrame.
- Reach for `F.col("name")`, or a bare string where the API accepts one.
- Attribute access (`df.amount`) and subscript access (`df["amount"]`) both bind the expression to one variable.
- Attribute access is fine in exactly one place: disambiguating same-named columns after a join, via aliases.
- Column expressions built with `F.col` are portable — you can hoist them into module-level constants and reuse them.
def enrich(orders):return (orders.withColumn('is_bulk', orders.quantity > 100).filter(orders['status'] == 'PAID'))
def enrich(orders):return (orders.withColumn('is_bulk', F.col('quantity') > 100).filter(F.col('status') == 'PAID'))
What changed: The expressions no longer mention `orders`, so they survive being extracted into a shared helper.
Palantir style guide