Data Analysis

作者 bytedancefb0ed9c96076无许可证83K 个星标收录于 2026年10月8日更新于 2026年10月8日仓库今天更新

Use 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, joins, and exporting results to CSV/JSON/Markdown.

包含脚本Data & Analytics
AI 生成的概览

使用 DuckDB SQL 查询、统计摘要和结果导出功能分析上传的 Excel 和 CSV 文件。

功能
该技能检查上传的 Excel 和 CSV 文件,报告工作表、列、类型、行数和示例行。它通过 DuckDB 运行 SQL 查询,包括聚合、跨文件连接、窗口函数和透视式分析,并生成数值列和字符串列的统计摘要。结果可导出为 CSV、JSON 或 Markdown 文件,加载的数据会缓存在持久化 DuckDB 数据库中。
适用场景
当用户上传 .xlsx、.xls 或 CSV 文件并希望进行结构化数据探索、统计、摘要、透视表或基于 SQL 的查询时使用。它也适用于多工作表工作簿和需要导出结果或以表格形式呈现的跨文件连接。
运行要求
需要 Python 和 DuckDB 引擎,以及随附的 scripts/analyze.py 脚本。它从 /mnt/user-data/uploads/ 读取文件,可将输出写入 /mnt/user-data/outputs/;缓存使用 /mnt/user-data/workspace/.data-analysis-cache/。未提及凭据或网络访问。

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:

bash
python /mnt/skills/public/data-analysis/scripts/analyze.py \  --files /mnt/user-data/uploads/data.xlsx \  --action inspect

This returns:

  • 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
bash
python /mnt/skills/public/data-analysis/scripts/analyze.py \  --files /mnt/user-data/uploads/data.xlsx \  --action query \  --sql "SELECT category, COUNT(*) as count, AVG(amount) as avg_amount FROM Sheet1 GROUP BY category ORDER BY count DESC"
Generate Statistical Summary
bash
python /mnt/skills/public/data-analysis/scripts/analyze.py \  --files /mnt/user-data/uploads/data.xlsx \  --action summary \  --table Sheet1

This returns for each numeric column: count, mean, std, min, 25%, 50%, 75%, max, null_count. For string columns: count, unique, top value, frequency, null_count.

Export Results
bash
python /mnt/skills/public/data-analysis/scripts/analyze.py \  --files /mnt/user-data/uploads/data.xlsx \  --action query \  --sql "SELECT * FROM Sheet1 WHERE amount > 1000" \  --output-file /mnt/user-data/outputs/filtered-results.csv

Supported output formats (auto-detected from extension):

  • .csv — Comma-separated values
  • .json — JSON array of records
  • .md — Markdown table

Parameters

ParameterRequiredDescription
--filesYesSpace-separated paths to Excel/CSV files
--actionYesOne of: inspect, query, summary
--sqlFor querySQL query to execute
--tableFor summaryTable/sheet name to summarize
--output-fileNoPath to export results (CSV/JSON/MD)

[!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

sql
-- Row countSELECT COUNT(*) FROM Sheet1
-- Distinct values in a columnSELECT DISTINCT category FROM Sheet1
-- Value distributionSELECT category, COUNT(*) as cnt FROM Sheet1 GROUP BY category ORDER BY cnt DESC
-- Date rangeSELECT MIN(date_col), MAX(date_col) FROM Sheet1

Aggregation & Grouping

sql
-- Revenue by category and monthSELECT category, DATE_TRUNC('month', order_date) as month,       SUM(revenue) as total_revenueFROM SalesGROUP BY category, monthORDER BY month, total_revenue DESC
-- Top 10 customers by spendSELECT customer_name, SUM(amount) as total_spendFROM Orders GROUP BY customer_nameORDER BY total_spend DESC LIMIT 10

Cross-file Joins

sql
-- Join sales with customer info from different filesSELECT s.order_id, s.amount, c.customer_name, c.regionFROM sales sJOIN customers c ON s.customer_id = c.idWHERE s.amount > 500

Window Functions

sql
-- Running total and rankSELECT order_date, amount,       SUM(amount) OVER (ORDER BY order_date) as running_total,       RANK() OVER (ORDER BY amount DESC) as amount_rankFROM Sales

Pivot-style Analysis

sql
-- Pivot: monthly revenue by categorySELECT category,       SUM(CASE WHEN MONTH(date) = 1 THEN revenue END) as Jan,       SUM(CASE WHEN MONTH(date) = 2 THEN revenue END) as Feb,       SUM(CASE WHEN MONTH(date) = 3 THEN revenue END) as MarFROM SalesGROUP BY category

Complete Example

User uploads sales_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

bash
python /mnt/skills/public/data-analysis/scripts/analyze.py \  --files /mnt/user-data/uploads/sales_2024.xlsx \  --action inspect

Step 2: Top products by revenue

bash
python /mnt/skills/public/data-analysis/scripts/analyze.py \  --files /mnt/user-data/uploads/sales_2024.xlsx \  --action query \  --sql "SELECT p.product_name, SUM(o.quantity * o.unit_price) as total_revenue, SUM(o.quantity) as total_units FROM Orders o JOIN Products p ON o.product_id = p.id GROUP BY p.product_name ORDER BY total_revenue DESC LIMIT 10"

Step 3: Monthly revenue trends

bash
python /mnt/skills/public/data-analysis/scripts/analyze.py \  --files /mnt/user-data/uploads/sales_2024.xlsx \  --action query \  --sql "SELECT DATE_TRUNC('month', order_date) as month, SUM(quantity * unit_price) as revenue FROM Orders GROUP BY month ORDER BY month" \  --output-file /mnt/user-data/outputs/monthly-trends.csv

Step 4: Statistical summary

bash
python /mnt/skills/public/data-analysis/scripts/analyze.py \  --files /mnt/user-data/uploads/sales_2024.xlsx \  --action summary \  --table Orders

Present results to the user with clear explanations of findings, trends, and actionable insights.

Multi-file Example

User uploads orders.csv and customers.xlsx and asks: "Which region has the highest average order value?"

bash
python /mnt/skills/public/data-analysis/scripts/analyze.py \  --files /mnt/user-data/uploads/orders.csv /mnt/user-data/uploads/customers.xlsx \  --action query \  --sql "SELECT c.region, AVG(o.amount) as avg_order_value, COUNT(*) as order_count FROM orders o JOIN Customers c ON o.customer_id = c.id GROUP BY c.region ORDER BY avg_order_value DESC"

Output Handling

After analysis:

  • Present query results directly in conversation as formatted tables
  • For large results, export to file and share via present_files tool
  • 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

This is especially useful when running multiple queries against the same data files (inspect → query → summary).

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"

来源与署名

来源:bytedance/deer-flow位于skills/public/data-analysis提交fb0ed9c

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架