Polars DataFrames in Python
Building a DataFrame and inspecting it.
import polars as pl
df = pl.DataFrame({
"name": ["ada", "grace", "katherine", "alan"],
"lang": ["python", "python", "rust", "go"],
"score": [95, 88, 92, 81],
})
shape = df.shape
columns = df.columns
head = df.head(2)
described = df.describe()
scores = df["score"]
average = scores.mean()
How it works
- A dict of columns constructs the frame.
shape,columns, andheaddescribe it.- Indexing a column gives a Series to aggregate.
Keywords and builtins used here
as
The run, in numbers
- Lines
- 15
- Characters to type
- 290
- Tokens
- 111
- Three-star pace
- 100 tpm
At the three-star pace of 100 tokens a minute, this run takes about 67 seconds.
Step 2 of 4 in Series & frames, step 2 of 32 in Polars.