typestar

DataFrame in Python

A DataFrame is a dict of Series that share one index.

import pandas as pd

frame = pd.DataFrame({
    "lang": ["python", "rust", "sql"],
    "tours": [11, 12, 3],
    "tpm": [104.5, 98.0, 88.5],
})

print(frame.shape, list(frame.columns))
print(frame.dtypes)
print(frame.head(2))
print(frame.describe().round(2))

How it works

  1. Building from a dict makes each key a column.
  2. shape, columns and dtypes describe it.
  3. head is how you look without printing everything.

Keywords and builtins used here

The run, in numbers

Lines
12
Characters to type
246
Tokens
96
Three-star pace
100 tpm

At the three-star pace of 100 tokens a minute, this run takes about 58 seconds.

Type this snippet

Step 2 of 4 in Series & frames, step 2 of 26 in pandas.

← Previous Next →