We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Basic Operations

Unlike Pandas, Polars leans hard on an expression-based API. You usually build expressions with the pl.col() function, which means "use this column in an operation."

Filter Rows

To filter for devices with temperatures above 80, use df.filter():

df.filter(pl.col("temperature_c") > 80)

Select Columns

To select the device_id and temperature_c columns, use df.select():

df.select(["device_id", "temperature_c"])
df.select(pl.col("device_id"), pl.col("temperature_c"))

Create Derived Columns

To add or replace columns, use df.with_columns(). For example, to convert Celsius readings to Fahrenheit:

df.with_columns(((pl.col("temperature_c") * 9 / 5) + 32).alias("temperature_f"))

The .alias() method names the new column.

Assignment

SnackStack's billing team needs a clean report of high-value transactions.

Complete the prepare_transaction_report function. It accepts a Polars DataFrame of transactions and returns a new, report-ready DataFrame.

Tips

  • You can build this report one step at a time, creating a variable for the return DataFrame and updating it with each operation.
  • Expressions often need to be nested. For example, pl.col() expressions will go inside the .filter() and .with_columns() calls.