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.