---
name: data-analysis
description: Use to inspect, clean, analyse or chart data in CSV, TSV, Excel (.xlsx) or JSON files - findings, tables and charts written up as a handbook report page - when the user asks to analyse data, find trends, compare numbers or make charts.
---
Analyse with code, never by eye: every number you report comes from a command you ran. Files you make (scripts, charts, the report) go into the session's working folder, with paths relative to it, never into your scratchpad: the user must be able to open them.
Keep the conversation small: every step re-sends all of it, and the user pays for each token. Read summaries, not data: never print a whole data file or table (`cat`, a long `head`, `print(df)`); your scripts print only results (totals, at most 60 rows of aggregates). The helpers below print one short line about what they did: do not read their source, the chart files or the report page back. Make independent commands one step (chain them in one `bash` call).
Work in the session's working folder (the working directory your context names): `bash` commands already start there, so use relative paths and no `cd`; never work in `` or a folder above the working folder. Helpers: `/scripts/` (`` = this skill's base directory, shown at the end of this text), Python 3 standard library (`python3`, else `python`).
1. **Profile** each file: `python3 /scripts/profile.py data/sales.csv` (also `.tsv`, `.json`, `.xlsx`; for a workbook add `--sheet NAME --csv data/sheet.csv` to get a CSV for your scripts). It prints rows, columns, types, missing values, duplicates, odd values, min/max/mean/sum per number column and the first rows, in at most 6,000 characters. Tell the user in two or three lines what the data holds and any quality problems.
2. **Clean** only when needed, into a new file (`analysis/clean.csv`), never over the original; note each change.
3. **Analyse** with one script, `analysis/analysis.py` (kept so the numbers can be checked and re-run), that prints the answers compactly, tables sorted (highest first) so every ranking you write comes from the output. Use the standard library (`csv`, `statistics`); pandas and openpyxl are often not installed. First decide what each column means (a total per row, a count, a price per unit) from its name, the question and the profile, say so in the report when it could be read two ways, and check your totals against the profile's sums (group totals add up to the column sum). Say how confident each finding is (small groups, missing data); correlation is not cause.
4. **Charts**: 1-4, each answering one question, written to files (all in one `bash` call):
`python3 /scripts/svg_chart.py data/sales.csv month revenue --agg sum --kind line --title "Revenue by month" --out analysis/revenue-by-month.svg.html`
`--agg sum|mean|count` groups the raw rows by the label column (first-seen order); `--series region` adds one bar or line per region (at most 4); without `--agg` the CSV must already have one row per label (at most 60). `--kind bar|line`; `--unit " EUR"` only when the data names its unit (never guess a currency). The chart uses the handbook's colour tokens, so it reads in light and dark.
5. **Report**: write only the body to `analysis/report-body.html`: a first `
` with the answer, then `Scope
` (the question, the data), `Method
` (cleaning and method, the script as `analysis/analysis.py`) and `Results
` (3-6 bullet findings with their numbers first, one marker line `` per chart, a small summary table). Never add a unit or currency the data does not state. No `