

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
Not enough gems
Cost: 6 gems
1: Polars
incomplete
2: Basic Operations
incomplete
3: Polars vs. Pandas
incomplete
4: Expression-Based Operations
incomplete
5: Lazy vs. Eager Execution
incomplete
6: No Index
incomplete
7: Filtering With No Index
incomplete
8: Index Alternatives
incomplete
9: Sorting
incomplete
10: Sorting Footguns
incomplete
11: Time-Based Operations
incomplete
12: Parquet
incomplete
13: Parquet With Polars
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
For an individual operation, Polars' expression-based syntax may not feel all that different from the equivalent in Pandas.
# Polars
df.filter(pl.col("level") > 25)
# Pandas
df[df["level"] > 25]
But if you have a sequence of operations to carry out, the expression-based system can feel much cleaner.
result = (
df.filter(pl.col("region") == "west")
.with_columns(
(pl.col("tickets_closed") / pl.col("hours_worked")).alias("tickets_per_hour")
)
.sort("tickets_per_hour", descending=True)
)
filtered_df = df[df["region"] == "west"].copy()
filtered_df["tickets_per_hour"] = (
filtered_df["tickets_closed"] / filtered_df["hours_worked"]
)
result = filtered_df.sort_values("tickets_per_hour", ascending=False)
The Pandas version works, but the transformation is split across multiple names and stores intermediate DataFrames. In Polars, each operation returns a DataFrame that can be passed directly into the next method.
Polars prefers expressions because they're readable (the step-by-step transformation is laid out in order), optimizable (Polars can plan the execution), and composable (they're simple to combine and reuse).
Pandas now also has tools for chaining, like .pipe(), but expressions are built into Polars from the ground up.
The SnackStack telemetry team needs a compact report of devices with high temperature readings.
Complete the build_temperature_report function. It accepts a Polars DataFrame of device readings and returns a new DataFrame.
Using one chain of expressions: