DEVSAIO

Analyse CSV data with AI (without hallucinated numbers)

The right way to use AI on spreadsheets: let code do the maths and the model do the reasoning and writing.

DEVSAIO team · 1 min read
Share on X

Pasting a big CSV into a chat and asking “what's the average?” is a recipe for wrong numbers. Models aren't calculators. The reliable pattern is:

  1. Code computes the numbers.
  2. The model interprets them and writes the explanation.

1. Profile the data with pandas

python
import pandas as pd
df = pd.read_csv("sales.csv", parse_dates=["date"])

profile = {
    "rows": len(df),
    "columns": {c: str(t) for c, t in df.dtypes.items()},
    "by_month": df.groupby(df["date"].dt.to_period("M"))["revenue"].sum().round(2).astype(str).to_dict(),
    "top_products": df.groupby("product")["revenue"].sum().nlargest(10).round(2).to_dict(),
    "by_region": df.groupby("region")["revenue"].agg(["sum", "mean", "count"]).round(2).to_dict(),
}

2. Ask for insights on the summary

python
import json
r = client.chat.completions.create(model="claude-sonnet-4-6", messages=[{"role": "user", "content":
    "You are a data analyst. Using ONLY these computed figures, write: 3 key findings, 2 anomalies worth checking, "
    "and 3 questions to investigate next. Quote numbers exactly as given.\n\n" + json.dumps(profile, default=str)}])
print(r.choices[0].message.content)

3. Let the model write the analysis code

For follow-up questions, ask the model for pandas code instead of an answer, review it, and run it yourself:

text
Given a DataFrame `df` with columns {columns}, write pandas code that answers: "Which region grew fastest quarter over quarter?" Output only code.

That way every number comes from your data, not from the model's guess.

Try it with one API key

Claude, GPT, Gemini, DeepSeek, image and video models through one OpenAI- and Anthropic-compatible endpoint. Prepaid, pay only for what you use.

Keep reading