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
After you export a file, read it back with read_csv and check that the totals still match. Open every file before you send it, even for ten seconds. This one-minute habit helps you catch a broken export before your manager sees it in a meeting.
Ravindra Bagale's Tip – मराठी
File export केल्यानंतर ती read_csv ने परत वाचा आणि totals अजूनही जुळतात का ते तपासा. प्रत्येक file पाठवण्याआधी उघडून पाहा, अगदी दहा seconds साठी तरी. या एका मिनिटाच्या सवयीमुळे खराब export manager ला meeting मध्ये दिसण्याआधीच तुम्हाला सापडतो.
Ravindra Bagale's Tip – हिंदी
File export करने के बाद उसे read_csv से वापस पढ़ो और देखो कि totals अब भी match करते हैं। हर file भेजने से पहले खोलकर देखो, चाहे दस seconds के लिए ही। इस एक मिनट की आदत से खराब export manager को meeting में दिखने से पहले ही आपको मिल जाता है।