22. Exporting and Sharing Your Analysis
22.6 Common Export Mistakes
Why. Silent export bugs waste a full morning in ops groups — especially around Indian thousand commas and encoding.
What. Frequent pitfalls:
- Leaving the DataFrame index as a mystery column in CSV.
- Writing amounts that still contain
"1,299"as text. - Excel opening CSV and re-saving with broken UTF-8.
- Forgetting
dayfirstwhen round-tripping dates. - Sending a chart with no title or units.
- Overwriting
raw/.
How.
Pre-send checklist
df.dtypes— amounts are numeric (int/float), notobject.df.to_csv(..., index=False).- Re-read with
pd.read_csvand compareshape+amount.sum(). - Open PNG; zoom on phone if that is the channel.
- Confirm filename dates match the insight scope line.
Worked example A — Comma trap.
import pandas as pd
ugly = pd.DataFrame({"amount": ["1,299", "90", "2,499"]})
# Wrong: export as-is — Excel may treat as text or split columns
ugly.to_csv("outputs/bad_amounts.csv", index=False)
fixed = ugly.copy()
fixed["amount"] = (
fixed["amount"].astype(str).str.replace(",", "", regex=False).astype(float)
)
fixed.to_csv("outputs/good_amounts.csv", index=False)
print(pd.read_csv("outputs/good_amounts.csv")["amount"].sum()) # 3888.0
Worked example B — Index accident.
s = df.groupby("city")["amount"].sum()
s.to_csv("outputs/with_index_mystery.csv") # index becomes a column — OK if named
s.to_csv("outputs/with_index_false.csv", index=False) # city names LOST — bad
s.rename_axis("city").reset_index(name="gmv").to_csv(
"outputs/city_gmv.csv", index=False
)
Worked example C — Encoding peek.
text = pd.DataFrame({"city": ["Pune", "Sambhaji Nagar"], "note": ["ok", "rain delay"]})
text.to_csv("outputs/notes_utf8.csv", index=False, encoding="utf-8")
# Round-trip
print(pd.read_csv("outputs/notes_utf8.csv", encoding="utf-8"))
If a partner only uses Excel on older Windows and complains, offer utf-8-sig and keep the utf-8 original in outputs/.
Ravindra Bagale's Tip
Export kele ki parat read_csv karun sum match kara. Hi ek minute chi discipline hours vachavte.