Ravindra BagaleCourses & study guides मराठी Track your progress

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:

  1. Leaving the DataFrame index as a mystery column in CSV.
  2. Writing amounts that still contain "1,299" as text.
  3. Excel opening CSV and re-saving with broken UTF-8.
  4. Forgetting dayfirst when round-tripping dates.
  5. Sending a chart with no title or units.
  6. Overwriting raw/.

How.

Pre-send checklist

  1. df.dtypes — amounts are numeric (int/float), not object.
  2. df.to_csv(..., index=False).
  3. Re-read with pd.read_csv and compare shape + amount.sum().
  4. Open PNG; zoom on phone if that is the channel.
  5. 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.