
Reading Only Some Columns of a Large CSV With pandas
Use usecols, dtype, nrows and chunksize to load a large CSV into pandas with a fraction of the memory. Measured on 2,000,000 rows, with the float32 trap.
The format everyone exports and nobody specifies. Delimiters, quoting, encodings and loading it into a database intact.

Use usecols, dtype, nrows and chunksize to load a large CSV into pandas with a fraction of the memory. Measured on 2,000,000 rows, with the float32 trap.

What DtypeWarning mixed types means in pandas read_csv, how it splits one column into ints and strings, and three ways to fix it, with counts.

Make pandas read_csv cope with title lines, comments, European numbers, odd NA markers, short or long rows and the wrong encoding, one option at a time.

Write CSV in Python with csv.writer and DictWriter: newline='', the quoting modes, how None, floats, dates and bytes are written, and what Excel needs.

csv.DictReader turns each CSV row into a dict keyed by the header. See what it does with missing and extra fields, BOMs, duplicate headers and blank lines.

Read CSV in Python with csv.reader: open with newline='', handle quoted commas and multi-line fields, set the dialect, and stream millions of rows.

A working guide to CSV in Python: csv module, DictReader, pandas, polars and DuckDB measured on 2,000,000 rows, plus the encoding, quoting and type rules.

Export a DuckDB query to CSV with COPY. Control the delimiter, NULL text, quoting, date format and compression, and split output into one file per value.

Join two CSV files on a key with plain SQL in DuckDB. Covers a 2M by 250k row join, keys that differ by case and spaces, left and anti joins, and type errors.

One COPY statement turns a CSV into Parquet in DuckDB. See the schema it writes, fix zip and money columns, compare compression codecs, and verify the result.

Use ignore_errors and store_rejects in DuckDB to read past bad CSV rows, then query reject_errors to see which lines were dropped and why.

A date column with five formats makes DuckDB fall back to text. Parse it with try_strptime and coalesce, list the failures, and avoid the day-first trap.
We send one email when a new article is published. No spam.