Aan de slagBegin gratis

Fast-path filter on sorted data

The historical analysis team needs every checkout record from before 2021. The CSV is already sorted by date, so if you tell Polars about that, it can stop scanning as soon as the first 2021 row appears.

Deze oefening maakt deel uit van de cursus

Scaling and Optimizing Data Pipelines with Polars

Bekijk cursus

Oefeninstructies

  • Mark the date column as sorted so Polars can use a fast-path scan.
  • Filter to rows where date is before January 1, 2021.
  • Execute the lazy query.

Interactieve oefening met praktijkervaring

Probeer deze oefening door deze voorbeeldcode aan te vullen.

result = (
    library
    # Mark date as sorted to enable the fast-path scan
    .____("date")
    # Filter to rows before 2021-01-01
    .filter(pl.col("date") < pl.____(2021, 1, 1))
    # Execute the lazy query
    .____()
)
print(result.head())
Code bewerken en uitvoeren