Skip to content
M365-26 Field-tested

Tenant CSV exports: BOM handling

Microsoft CSV exports start with a byte-order mark that breaks the first column name. Read them with utf-8-sig.

Symptom

Reading a Microsoft 365 or Azure CSV export in Python fails on the first column: KeyError: 'Name', although the column is clearly there.

Cause

The file starts with a UTF-8 byte-order mark (BOM). It gets glued to the first header, which becomes '\ufeffName'.

Fix

Python:

import csv
with open("export.csv", encoding="utf-8-sig", newline="") as f:
    rows = list(csv.DictReader(f))

pandas: pd.read_csv("export.csv", encoding="utf-8-sig")

PowerShell’s Import-Csv handles the BOM already.

Seeing this in your environment?

We can check for this, and everything around it, as part of an audit.

Ask us about M365-26

Find out what's really going on in your tenant.

Tell us what you run and what's worrying you. We'll recommend the right audit, and tell you honestly if you don't need one.