$npx -y skills add MagicCube/agentara --skill data-analysisUse this skill when the user uploads Excel (.xlsx/.xls) or CSV files and wants to perform data analysis, generate statistics, create summaries, pivot tables, SQL queries, or any form of structured data exploration. Supports multi-sheet Excel workbooks, aggregation, filtering, joi
| 1 | # Data Analysis Skill |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | 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. |
| 6 | |
| 7 | ## Core Capabilities |
| 8 | |
| 9 | - Inspect Excel/CSV file structure (sheets, columns, types, row counts) |
| 10 | - Execute arbitrary SQL queries against uploaded data |
| 11 | - Generate statistical summaries (mean, median, stddev, percentiles, nulls) |
| 12 | - Support multi-sheet Excel workbooks (each sheet becomes a table) |
| 13 | - Export query results to CSV, JSON, or Markdown |
| 14 | - Handle large files efficiently with DuckDB's columnar engine |
| 15 | |
| 16 | ## Workflow |
| 17 | |
| 18 | ### Step 1: Understand Requirements |
| 19 | |
| 20 | When a user uploads data files and requests analysis, identify: |
| 21 | |
| 22 | - **File location**: Path(s) to uploaded Excel/CSV files under `/mnt/user-data/uploads/` |
| 23 | - **Analysis goal**: What insights the user wants (summary, filtering, aggregation, comparison, etc.) |
| 24 | - **Output format**: How results should be presented (table, CSV export, JSON, etc.) |
| 25 | - You don't need to check the folder under `/mnt/user-data` |
| 26 | |
| 27 | ### Step 2: Inspect File Structure |
| 28 | |
| 29 | First, inspect the uploaded file to understand its schema: |
| 30 | |
| 31 | ```bash |
| 32 | python /mnt/skills/public/data-analysis/scripts/analyze.py \ |
| 33 | --files /mnt/user-data/uploads/data.xlsx \ |
| 34 | --action inspect |
| 35 | ``` |
| 36 | |
| 37 | This returns: |
| 38 | - Sheet names (for Excel) or filename (for CSV) |
| 39 | - Column names, data types, and non-null counts |
| 40 | - Row count per sheet/file |
| 41 | - Sample data (first 5 rows) |
| 42 | |
| 43 | ### Step 3: Perform Analysis |
| 44 | |
| 45 | Based on the schema, construct SQL queries to answer the user's questions. |
| 46 | |
| 47 | #### Run SQL Query |
| 48 | |
| 49 | ```bash |
| 50 | python /mnt/skills/public/data-analysis/scripts/analyze.py \ |
| 51 | --files /mnt/user-data/uploads/data.xlsx \ |
| 52 | --action query \ |
| 53 | --sql "SELECT category, COUNT(*) as count, AVG(amount) as avg_amount FROM Sheet1 GROUP BY category ORDER BY count DESC" |
| 54 | ``` |
| 55 | |
| 56 | #### Generate Statistical Summary |
| 57 | |
| 58 | ```bash |
| 59 | python /mnt/skills/public/data-analysis/scripts/analyze.py \ |
| 60 | --files /mnt/user-data/uploads/data.xlsx \ |
| 61 | --action summary \ |
| 62 | --table Sheet1 |
| 63 | ``` |
| 64 | |
| 65 | This returns for each numeric column: count, mean, std, min, 25%, 50%, 75%, max, null_count. |
| 66 | For string columns: count, unique, top value, frequency, null_count. |
| 67 | |
| 68 | #### Export Results |
| 69 | |
| 70 | ```bash |
| 71 | python /mnt/skills/public/data-analysis/scripts/analyze.py \ |
| 72 | --files /mnt/user-data/uploads/data.xlsx \ |
| 73 | --action query \ |
| 74 | --sql "SELECT * FROM Sheet1 WHERE amount > 1000" \ |
| 75 | --output-file /mnt/user-data/outputs/filtered-results.csv |
| 76 | ``` |
| 77 | |
| 78 | Supported output formats (auto-detected from extension): |
| 79 | - `.csv` — Comma-separated values |
| 80 | - `.json` — JSON array of records |
| 81 | - `.md` — Markdown table |
| 82 | |
| 83 | ### Parameters |
| 84 | |
| 85 | | Parameter | Required | Description | |
| 86 | |-----------|----------|-------------| |
| 87 | | `--files` | Yes | Space-separated paths to Excel/CSV files | |
| 88 | | `--action` | Yes | One of: `inspect`, `query`, `summary` | |
| 89 | | `--sql` | For `query` | SQL query to execute | |
| 90 | | `--table` | For `summary` | Table/sheet name to summarize | |
| 91 | | `--output-file` | No | Path to export results (CSV/JSON/MD) | |
| 92 | |
| 93 | > [!NOTE] |
| 94 | > Do NOT read the Python file, just call it with the parameters. |
| 95 | |
| 96 | ## Table Naming Rules |
| 97 | |
| 98 | - **Excel files**: Each sheet becomes a table named after the sheet (e.g., `Sheet1`, `Sales`, `Revenue`) |
| 99 | - **CSV files**: Table name is the filename without extension (e.g., `data.csv` → `data`) |
| 100 | - **Multiple files**: All tables from all files are available in the same query context, enabling cross-file joins |
| 101 | - **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"` |
| 102 | |
| 103 | ## Analysis Patterns |
| 104 | |
| 105 | ### Basic Exploration |
| 106 | ```sql |
| 107 | -- Row count |
| 108 | SELECT COUNT(*) FROM Sheet1 |
| 109 | |
| 110 | -- Distinct values in a column |
| 111 | SELECT DISTINCT category FROM Sheet1 |
| 112 | |
| 113 | -- Value distribution |
| 114 | SELECT category, COUNT(*) as cnt FROM Sheet1 GROUP BY category ORDER BY cnt DESC |
| 115 | |
| 116 | -- Date range |
| 117 | SELECT MIN(date_col), MAX(date_col) FROM Sheet1 |
| 118 | ``` |
| 119 | |
| 120 | ### Aggregation & Grouping |
| 121 | ```sql |
| 122 | -- Revenue by category and month |
| 123 | SELECT category, DATE_TRUNC('month', order_date) as month, |
| 124 | SUM(revenue) as total_revenue |
| 125 | FROM Sales |
| 126 | GROUP BY category, month |
| 127 | ORDER BY month, total_revenue DESC |
| 128 | |
| 129 | -- Top 10 customers by spend |
| 130 | SELECT customer_name, SUM(amount) as total_spend |
| 131 | FROM Orders GROUP BY customer_name |
| 132 | ORDER BY total_spend DESC LIMIT 10 |
| 133 | ``` |
| 134 | |
| 135 | ### Cross-file Joins |
| 136 | ```sql |
| 137 | -- Join sales with customer info from different files |
| 138 | SELECT s.order_id, s.amount, c.customer_name, c.region |
| 139 | FROM sales s |
| 140 | JOIN customers c ON s.customer_id = c.id |
| 141 | W |