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
StringIOlets you parse a literal, handy for testing.dtypeandparse_datesbeat converting afterwards.usecolsreads only the columns you need.
Keywords and builtins used here
asprint
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.
Step 3 of 4 in Series & frames, step 3 of 26 in pandas.