typestar

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

  1. A dict of columns constructs the frame.
  2. shape, columns, and head describe it.
  3. Indexing a column gives a Series to aggregate.

Keywords and builtins used here

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.

Type this snippet

Step 2 of 4 in Series & frames, step 2 of 32 in Polars.

← Previous Next →