
Fixing BadZipFile When Reading an XLSX With Python
Fix zipfile.BadZipFile File is not a zip file when openpyxl or pandas reads an xlsx: wrong content, empty or truncated file, encryption and upload mistakes.
Tag
134 posts

Fix zipfile.BadZipFile File is not a zip file when openpyxl or pandas reads an xlsx: wrong content, empty or truncated file, encryption and upload mistakes.

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.

Fix XLRDError Excel xlsx file not supported in pandas and Python: xlrd 2 reads only old xls files, so install openpyxl and pick the right engine.

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.

Turn an RSS podcast feed into cadence, duration and size numbers, handle itunes durations in two formats and RFC 822 dates, and compare with feedparser.

How a YAML tag makes PyYAML run code during load, a harmless demonstration, what changed in PyYAML 6 and the safe options for loading untrusted files.

A tested Python guide to YAML: safe loading, speed, strict keys, validation, clean output, round trips, merging, env substitution and a reference module.

Build XML from CSV rows without string templates that break on an ampersand. Use lxml or escape every value, and handle control characters and empty cells.

Write an XML file into an xlsx workbook with openpyxl so numbers are numbers, booleans are booleans and identifiers stay text, and read it back to check.

A working guide to openpyxl: the workbook model, reading values and formulas, writing and editing files, large-file modes, styles, charts and errors.

Freeze the header row, add filter buttons and set column widths from Python with openpyxl and XlsxWriter, including an auto-width helper and print settings.