Shrink a CSV Before Uploading It to ChatGPT Data Analysis
Measure a big CSV with pandas, then cut it down before upload: drop columns, split by month, or aggregate by day. A 285 MB file becomes 6 to 8 MB.
If a 1.5-million-row CSV stalls in ChatGPT or ends in "Analysis errored", shrink it on your own machine first. The numbers below were measured on a synthetic transactions file (1.5M rows, 12 columns).
[1] Check the file size and line count.
$ ls -l sales.csv-rw-r--r-- 1 user user 285648280 Oct 19 14:35 sales.csv$ wc -l sales.csv1500001 sales.csvOpenAI's File Uploads FAQ says a CSV or spreadsheet cannot exceed roughly 50 MB, depending on row size. A 285 MB file is over that before you even start.
[2] Measure memory when pandas loads it. Save this as measure.py.
import sys, time, resource, pandas as pdmode, path = sys.argv[1], sys.argv[2]cols = ["created_at", "store_code", "category", "status", "quantity", "unit_price"]t = time.time()if mode == "full": df = pd.read_csv(path)elif mode == "usecols": df = pd.read_csv(path, usecols=cols)else: df = pd.read_csv(path, usecols=cols, parse_dates=["created_at"], dtype={"store_code": "category", "category": "category", "status": "category", "quantity": "uint8", "unit_price": "float32"})mem = df.memory_usage(deep=True).sum() / 2**20rss = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1024print(mode, "rows", len(df), "mem_MB %.0f" % mem, "peakRSS_MB %.0f" % rss, "sec %.1f" % (time.time() - t))$ python3 measure.py full sales.csvfull rows 1500000 mem_MB 832 peakRSS_MB 523 sec 7.0mem_MB is the DataFrame size; peakRSS_MB is the most memory the process actually held. They differ, so record both.
[3] Drop the columns you will not use. Reading with usecols skips long text columns such as transaction_id, customer_id, memo and user_agent.
$ python3 measure.py usecols sales.csvusecols rows 1500000 mem_MB 353 peakRSS_MB 294 sec 4.1[4] Shrink the dtypes. Read low-cardinality strings as category, small integers as uint8, and dates with parse_dates.
$ python3 measure.py dtype sales.csvdtype rows 1500000 mem_MB 23 peakRSS_MB 213 sec 3.1| How it was read | DataFrame | Peak memory |
|---|---|---|
| All 12 columns | 832 MB | 523 MB |
| 6 columns | 353 MB | 294 MB |
| 6 columns + dtypes | 23 MB | 213 MB |
[5] Save only the needed columns as a new CSV. That took 285.6 MB down to 72.4 MB, but the row count is unchanged, so it is still above 50 MB. Also write a monthly split and an aggregate.
import sys, pandas as pdsrc, out = sys.argv[1], sys.argv[2]df = pd.read_csv(src, usecols=["created_at", "store_code", "category", "status", "quantity", "unit_price"], parse_dates=["created_at"])df.to_csv(out + "/sales_slim.csv", index=False) df["month"] = df["created_at"].dt.strftime("%Y-%m")for m, g in df.groupby("month"): g.drop(columns="month").to_csv(f"{out}/sales_{m}.csv", index=False) d = df.assign(day=df["created_at"].dt.date, amount=df.quantity * df.unit_price)d.groupby(["day", "store_code", "category", "status"], as_index=False) \ .agg(orders=("amount", "size"), amount=("amount", "sum")).round(2) \ .to_csv(out + "/sales_daily.csv", index=False)$ mkdir out && python3 shrink.py sales.csv out$ ls -l out-rw-r--r-- 1 user user 6141315 Oct 19 14:36 sales_2025-01.csv-rw-r--r-- 1 user user 5558707 Oct 19 14:36 sales_2025-02.csv…-rw-r--r-- 1 user user 6116954 Oct 19 14:36 sales_2025-12.csv-rw-r--r-- 1 user user 7910740 Oct 19 14:36 sales_daily.csv-rw-r--r-- 1 user user 72359492 Oct 19 14:35 sales_slim.csv[6] Pick the file that fits the question. To inspect individual rows, upload only the month you need (about 6 MB). For totals, trends and comparisons, sales_daily.csv (187,346 rows, 7.9 MB) is enough.
[7] Check the row count and header before uploading. For the aggregate, say in your prompt that one row is one day, store, category and status total, so row count is not mistaken for order count.
$ wc -l out/sales_daily.csv187347 out/sales_daily.csv$ head -3 out/sales_daily.csvday,store_code,category,status,orders,amount2025-01-01,ST000,clothing,paid,21,46394.812025-01-01,ST000,clothing,refunded,1,3595.68[8] If "Analysis errored" still appears, separate the causes. For an odd delimiter or encoding, inspect with head and re-save as UTF-8. If the file is still large, split or aggregate further as in step 5. If one chat keeps failing, start a new chat and upload only the reduced file.