

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 4
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
In Pandas, every DataFrame has an index:
df = pd.DataFrame(
{"player": ["Sam", "Dario"], "level": [10, 20]},
index=["closedai", "clawd"],
)
print(df)
# player level
# closedai Sam 10
# clawd Dario 20The closedai and clawd labels on the left are index labels. Pandas lets you define custom indexes, reset them, and use them for selection.
Polars does not have a Pandas-style index. Here's the same data in Polars:
df = pl.DataFrame({"player": ["Sam", "Dario"], "level": [10, 20]})
print(df)
# shape: (2, 2)
# ┌────────┬───────┐
# │ player ┆ level │
# │ --- ┆ --- │
# │ str ┆ i64 │
# ╞════════╪═══════╡
# │ Sam ┆ 10 │
# │ Dario ┆ 20 │
# └────────┴───────┘No index labels at all. Rows are identified by position, and any other kind of identifier that you want to add should go in a normal column.
The Pandas index exists for complicated historical reasons. It can be convenient, but it's also a common source of confusion, and it creates extra rules around filtering, alignment, and joins.
Polars takes the simpler route: no hidden row labels. That means you have to be more explicit about what you want when joining and filtering data, which is usually a good tradeoff.