Data Analysis Skill
Overview
This skill analyzes user-uploaded Excel/CSV files using DuckDB — an in-process analytical SQL engine. It supports schema inspection, SQL-based querying, statistical summaries, and result export, all through a single Python script.Core Capabilities
- Inspect Excel/CSV file structure (sheets, columns, types, row counts)
- Execute arbitrary SQL queries against uploaded data
- Generate statistical summaries (mean, median, stddev, percentiles, nulls)
- Support multi-sheet Excel workbooks (each sheet becomes a table)
- Export query results to CSV, JSON, or Markdown
- Handle large files efficiently with DuckDB’s columnar engine
Workflow
Step 1: Understand Requirements
When a user uploads data files and requests analysis, identify:- File location: Path(s) to uploaded Excel/CSV files under
/mnt/user-data/uploads/ - Analysis goal: What insights the user wants (summary, filtering, aggregation, comparison, etc.)
- Output format: How results should be presented (table, CSV export, JSON, etc.)
- You don’t need to check the folder under
/mnt/user-data
Step 2: Inspect File Structure
First, inspect the uploaded file to understand its schema:- Sheet names (for Excel) or filename (for CSV)
- Column names, data types, and non-null counts
- Row count per sheet/file
- Sample data (first 5 rows)
Step 3: Perform Analysis
Based on the schema, construct SQL queries to answer the user’s questions.Run SQL Query
Generate Statistical Summary
Export Results
.csv— Comma-separated values.json— JSON array of records.md— Markdown table
Parameters
[!NOTE] Do NOT read the Python file, just call it with the parameters.
Table Naming Rules
- Excel files: Each sheet becomes a table named after the sheet (e.g.,
Sheet1,Sales,Revenue) - CSV files: Table name is the filename without extension (e.g.,
data.csv→data) - Multiple files: All tables from all files are available in the same query context, enabling cross-file joins
- Special characters: Sheet/file names with spaces or special characters are auto-sanitized (spaces → underscores). Use double quotes for names that start with numbers or contain special characters, e.g.,
"2024_Sales"
Analysis Patterns
Basic Exploration
Aggregation & Grouping
Cross-file Joins
Window Functions
Pivot-style Analysis
Complete Example
User uploadssales_2024.xlsx (with sheets: Orders, Products, Customers) and asks: “Analyze my sales data — show top products by revenue and monthly trends.”
Step 1: Inspect the file
Step 2: Top products by revenue
Step 3: Monthly revenue trends
Step 4: Statistical summary
Multi-file Example
User uploadsorders.csv and customers.xlsx and asks: “Which region has the highest average order value?”
Output Handling
After analysis:- Present query results directly in conversation as formatted tables
- For large results, export to file and share via
present_filestool - Always explain findings in plain language with key takeaways
- Suggest follow-up analyses when patterns are interesting
- Offer to export results if the user wants to keep them
Caching
The script automatically caches loaded data to avoid re-parsing files on every call:- On first load, files are parsed and stored in a persistent DuckDB database under
/mnt/user-data/workspace/.data-analysis-cache/ - The cache key is a SHA256 hash of all input file contents — if files change, a new cache is created
- Subsequent calls with the same files will use the cached database directly (near-instant startup)
- Cache is transparent — no extra parameters needed
Notes
- DuckDB supports full SQL including window functions, CTEs, subqueries, and advanced aggregations
- Excel date columns are automatically parsed; use DuckDB date functions (
DATE_TRUNC,EXTRACT, etc.) - For very large files (100MB+), DuckDB handles them efficiently without loading everything into memory
- Column names with spaces are accessible using double quotes:
"Column Name"