AI for spreadsheet analysis: CSV and Excel via API without wrong numbers
How to analyze CSV and Excel with a model via API: pandas computes the numbers, the model looks for patterns and writes findings as JSON, and code checks that each finding rests on a real metric.
6 min · · автоматизация · development
People search for "AI for spreadsheet analysis" when they have an export of sales, orders or reviews and no time to go through it by hand. The temptation is simple: send the model the whole CSV and ask "what's interesting here". Below: why you shouldn't, how to prepare the data in pandas, what to send instead of the whole table, how to get the answer as JSON, and what such an analysis costs.
Why you shouldn't send the whole table
Three reasons.
Arithmetic. A language model generates text; it doesn't run calculations. A sum over thousands of rows, an average, a growth rate or a count of rows matching a condition may come out plausible but wrong. The more rows, the higher the risk. So there is one rule: code computes all numbers, the model interprets them.
Size. A table takes a lot of tokens. Say a row with five or six columns is about 30 tokens (find the exact figure for your data from usage.prompt_tokens on a 100-row trial). Then 10,000 rows is about 300,000 input tokens, and 50,000 rows is about 1.5M — more than the 1M context of any model in the Zukko catalog.
Price. Even if the table fits, you pay for every input token on every question. The math is below.
AI for spreadsheet analysis: pandas computes, the model explains
- Load the table into pandas and clean it: types, missing values, duplicates.
- Compute in code the metrics the answer needs: totals, breakdowns by month and category, shares, missing values.
- Send the model a summary: metrics as JSON and 10–20 random rows so it understands the structure.
- Ask for a strict JSON answer in which each finding references a metric key.
- Check in code that the keys exist and substitute the real values.
Here the model does what it's good at: spotting patterns, forming hypotheses, suggesting what to check next. The numbers in the report always come from pandas.
Preparing CSV and Excel in pandas
CSV is read with pd.read_csv, Excel with pd.read_excel. .xlsx files need the openpyxl package (pip install pandas openpyxl). The sheet_name parameter selects a sheet; sheet_name=None returns a dict of all sheets.
Before sending, it's worth:
- converting dates and numbers to proper types (
parse_dates,pd.to_numeric(..., errors="coerce")); - counting missing values per column — the model should know where data is incomplete;
- dropping columns with personal data (names, phones, emails) if they aren't needed for the analysis: the random rows go into the request as is.
Example: analyzing a sales export
A sales.csv file with date, region, revenue columns. The script computes metrics, sends a summary and checks the answer:
import json
import pandas as pd
from openai import OpenAI
df = pd.read_csv("sales.csv", parse_dates=["date"]) # Excel: pd.read_excel(path, sheet_name=...)
df["month"] = df["date"].dt.to_period("M").astype(str)
metrics = { # pandas computes every number
"rows": int(len(df)),
"revenue_total": round(float(df["revenue"].sum()), 2),
"avg_order": round(float(df["revenue"].mean()), 2),
}What matters here:
- The
text.find("{")…rfind("}")slice cuts off any explanation or ```json wrapper around the object. Ifjson.loadsstill fails, retry the request or see the article on strict JSON responses, which covers thetoolsapproach. - The
metricfield ties each finding to a number from pandas. A finding without an existing metric is marked unverified, and the values in the report come from themetricsdict, not from the model's text. next_checksis the list of what the model suggests computing next. Compute those in code and, if needed, send a second request with the new metrics.
Where models get it wrong and what to compute in code
Hand to code everything involving a calculation or an exact count:
- sums, averages, medians, percentages and growth rates;
- counts of rows matching a condition ("how many orders above 10,000");
- sorting and top-N over long lists;
- averages of averages and shares on different bases — a common trap for people too;
- date operations: differences, weeks, seasonality.
You can give the model the wording of findings, spotting anomalies in breakdowns you've already computed, hypotheses ("the October dip may be because the month is incomplete — data only through the 5th"), classification of text columns and a draft report. If you want the model to suggest code for a calculation, run it only after review or in an isolated environment.
What spreadsheet analysis via API costs
Prices as of October 7, 2026, USD per 1M tokens. Formula for one request: (input × input price + output × output price) / 1,000,000.
A summary instead of the table. Metrics plus 20 rows come to about 3,000 input tokens, the answer about 800 tokens.
gpt-6.1-sol($0.27 / $1.32): (3,000 × 0.27 + 800 × 1.32) / 1,000,000 = (810 + 1,056) / 1,000,000 ≈ $0.0019 per report.gemini-3.8-flash($0.063 / $0.288): (3,000 × 0.063 + 800 × 0.288) / 1,000,000 = (189 + 230.4) / 1,000,000 ≈ $0.00042.
The whole table. 10,000 rows at 30 tokens = 300,000 input tokens, with the same 800 output.
gpt-6.1-sol: (300,000 × 0.27 + 800 × 1.32) / 1,000,000 = (81,000 + 1,056) / 1,000,000 ≈ $0.082 per question — with no guarantee the sums are right.
Row-by-row text processing. If the table has a comments column you need to label (topic, sentiment), that's a separate task: each row is a short request to a cheap model. 5,000 rows at 150 input and 20 output tokens:
deepseek-v4.1-flash($0.013 / $0.038): 5,000 × (150 × 0.013 + 20 × 0.038) / 1,000,000 = 5,000 × 2.71 / 1,000,000 ≈ $0.014;gemini-3.8-flash: 5,000 × (150 × 0.063 + 20 × 0.288) / 1,000,000 = 5,000 × 15.21 / 1,000,000 ≈ $0.076.
Labeling quality varies by model — run 50–100 rows with reference answers and compare. A detailed row-by-row labeling example is in the article review analysis from CSV to findings, and a similar scheme for incoming email is in AI for sorting email. For the current list and prices, call GET https://api.zukko.pro/v1/models or open the Models page in the dashboard.
If you want to try it on your own export, create a key on the API keys page; the request reference is in the chat/completions docs.
FAQ
Which AI model is best for spreadsheet analysis?
If the model only interprets computed metrics, start with an inexpensive one and compare it with a stronger one on a few of your own exports. The catalog's intelligence index is a guide (for example, GPT-6.1 Sol — 52, Gemini 3.8 Flash — 41), but testing on your data decides.
Can I send an Excel file directly?
A chat request carries text, so you first read the file in pandas (pd.read_excel, needs openpyxl) and turn it into metrics and a CSV fragment. That way you control exactly what reaches the model and how much.
What if the model still makes up a number?
Don't take numbers from the model's text at all. In the example above, values are filled in from the metrics dict, and a finding without an existing key is marked unverified.
How do I send a table larger than a million tokens?
You can't send it whole — and you don't need to. Reduce it to aggregates in pandas; if every row needs processing, handle rows in batches with separate requests.
zukko
Pay 25×
less
for Claude Code & ChatGPT
One fetch_* key and base URL api.zukko.pro — for Cursor, Claude Code, Codex, and any SDK.
Related articles
- Translating subtitles with a neural network: SRT without broken timecodesThe main risk when translating SRT with a neural network is a broken file structure. A scheme where timecodes never reach the model, and a Python script with validation.
- Editing texts with a neural network: proofreading, style and cuttingDifferent kinds of editing need different prompts. Wording for proofreading, style and cutting, how to get edits with explanations and how not to lose the author's voice.
- A neural network for writing scripts: Bash, PowerShell and PythonA model writes scripts for routine fast, but running them blindly is risky. How to state the task, demand a safe dry-run mode and check the result before launch.
- Dify in Docker: installation, first-run setup and connecting modelsInstall Dify with Docker Compose, create the admin account and connect Claude, GPT and DeepSeek models on one key. Plus what to do when containers will not start.