typestar

Reading CSV in Python

read_csv is the front door: point it at text, tell it the types.

from io import StringIO

import pandas as pd

raw = StringIO(
    "day,lang,tpm\n"
    "2026-07-28,python,104\n"
    "2026-07-29,rust,98\n"
)

frame = pd.read_csv(raw, parse_dates=["day"],
                    dtype={"lang": "string", "tpm": "int32"})
print(frame.dtypes)
print(frame)

How it works

  1. StringIO lets you parse a literal, handy for testing.
  2. dtype and parse_dates beat converting afterwards.
  3. usecols reads only the columns you need.

Keywords and builtins used here

The run, in numbers

Lines
14
Characters to type
251
Tokens
71
Three-star pace
100 tpm

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

Type this snippet

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

← Previous Next →