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

Filtering With No Index

In Pandas, when you filter, the index is preserved, which can be super confusing! That's why we had so much code that calls reset_index():

df = df[df["level"] > 10].reset_index(drop=True)

You don't need to worry about that in Polars because there's no index in the first place:

df = df.filter(pl.col("level") > 10)

Filtering just returns a new DataFrame with only the rows that match your condition. The whole "index preservation" is simply a non-issue:

result = df.filter(pl.col("level") > 10).filter(pl.col("gold") > 100)

Here's how you'd combine conditions in a single filter:

result = df.filter((pl.col("level") > 10) & (pl.col("gold") > 100))

The & operator (not and!) combines expressions in Polars, and each condition must be wrapped in parentheses.

Assignment

SnackStack's support team filters device status alerts into a "review queue" so they know the order in which to investigate them.

Complete the build_review_queue function. It accepts a Polars DataFrame of device alerts and returns a new DataFrame to serve as the review queue.

  1. Pass offset=1 into with_row_index to start the sequence at 1 instead of the default 0.

Notice how in Polars, with no built-in row index, we can just specify exactly what we want in a DataFrame selection.