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

Sorting

In Pandas, we can sort by a column or by the index:

# Sort by the price column
df = df.sort_values("price")

# Sort by index
df = df.sort_index()

In Polars, with no index available, the sort() method sorts by columns or expressions:

# Sort by the price column
df = df.sort("price")

Sort by Expression

Say we had a DataFrame of RPG character stats, and we wanted to sort by the sum of attack_rating and luck_bonus. In Pandas, you'd often create a temporary calculated column. In Polars, you can sort by an expression directly:

df = df.sort(pl.col("attack_rating") + pl.col("luck_bonus"))

Assignment

SnackStack's support team needs a queue of devices where those with the lowest combined battery_pct and signal_pct should be reviewed first.

Complete the build_service_queue function. It accepts a Polars DataFrame of device status rows and returns a new DataFrame.