csv-query

使用 Polars SQL 引擎对 CSV、TSV 或 Excel 文件执行 SQL 查询。

仓库最近推送
GitHub Stars
212
Forks
664
Issues / PRs
21

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "csv-query":https://skillpi.com/zh/skills/deepskill-f5167d8e5a4ae688a5fd7858a5fa3f5052a1b5e8a634a09ab3e6e6cf3d96a1fd。安装前核对上游来源和版本:https://github.com/Kilo-Org/kilo-marketplace。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

使用 Polars SQL 引擎对 CSV、TSV 或 Excel 文件执行 SQL 查询。

0 下载

介绍来源: third_party · Kilo-Org · 0.0.1 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: csv-query
description: Run SQL queries against CSV/TSV/Excel files using Polars SQL engine
allowed-tools:
  - mcp__qsv__qsv_sniff
  - mcp__qsv__qsv_count
  - mcp__qsv__qsv_headers
  - mcp__qsv__qsv_index
  - mcp__qsv__qsv_stats
  - mcp__qsv__qsv_frequency
  - mcp__qsv__qsv_search
  - mcp__qsv__qsv_select
  - mcp__qsv__qsv_sqlp
  - mcp__qsv__qsv_command
  - mcp__qsv__qsv_to_parquet
  - mcp__qsv__qsv_list_files
  - mcp__qsv__qsv_search_tools
  - mcp__qsv__qsv_get_working_dir
  - mcp__qsv__qsv_set_working_dir
metadata:
  upstream:
    user-invocable: true
    argument-hint: '<file> [query]'
  category: data
  source:
    repository: 'https://github.com/dathere/qsv'
    path: .claude/skills/skills/csv-query
    license_path: COPYING
    commit: d7bcd2d9ac92ca2edcc6086a1132ea2beb6ab079

CSV Query

Query tabular data files using SQL via the Polars-powered sqlp command.

Cowork note: If relative paths don't resolve, call mcp__qsv__qsv_get_working_dir and mcp__qsv__qsv_set_working_dir to sync the working directory.

Decision Tree

Is the query simple (single column filter, basic select)?

  • Yes -> Consider select + search for simpler operations
  • No -> Use sqlp for full SQL support

Does the query involve joins, GROUP BY, window functions, or complex expressions?

  • Yes -> Use sqlp (Polars SQL engine)

Is the CSV file very large (> 10MB)?

  • Yes -> Consider converting to Parquet with mcp__qsv__qsv_to_parquet for faster repeated queries. Note: sqlp can also query CSV files of any size directly.

Steps

  1. Prepare the file: Run mcp__qsv__qsv_index and mcp__qsv__qsv_stats with cardinality: true, stats_jsonl: true to create index and stats cache.

  2. Read the stats cache: Read <FILESTEM>.stats.csv (e.g., data.stats.csv for data.csv) to understand column metadata before writing SQL. This is the most important step for writing efficient queries.

  3. Run frequency on key columns: For columns you plan to GROUP BY, filter on, or join on, run mcp__qsv__qsv_frequency to see actual value distributions. This reveals the best filter values and whether a GROUP BY will produce a manageable result set.

  4. Write and run SQL: Use mcp__qsv__qsv_sqlp with the SQL query informed by stats and frequency data. The table name in SQL is the filename stem (e.g., data.csv -> SELECT * FROM data). For Parquet files, use read_parquet('data.parquet') as the table source instead.

  5. Refine if needed: Check results and adjust the query.

Using Stats to Write Better SQL

After reading the .stats.csv cache, use these columns to inform your SQL:

Stats Column How to Use in SQL
type Use correct casts and comparisons — don't quote integers, use date functions for Date/DateTime columns
min / max Write precise WHERE clauses using actual data range (e.g., WHERE price BETWEEN 10.5 AND 999.99 instead of arbitrary bounds)
cardinality Estimate GROUP BY result size — low cardinality (< 100) is fast; high cardinality (> 10K) may need LIMIT or a different approach
nullcount Only add COALESCE or IS NOT NULL where nullcount > 0 — skip null handling for columns with zero nulls
sort_order Skip ORDER BY if data is already sorted on that column (sort_order = "Ascending"/"Descending")
mean / stddev Write outlier filters: WHERE col BETWEEN mean - 3*stddev AND mean + 3*stddev
median / q1 / q3 For skewed data (when mean and median diverge), use quartile-based ranges: WHERE col BETWEEN q1 AND q3 instead of mean ± stddev
skewness If skewness > 1 or < -1, prefer median/quartile-based filters over mean-based ones
cv High CV (> 100%) signals high relative variability — add LIMIT to GROUP BY queries and consider binning continuous values
outliers_percentage If > 5%, consider excluding outliers before aggregation: WHERE col BETWEEN lower_inner_fence AND upper_inner_fence
sparsity Columns with sparsity > 0.5 are mostly null — avoid using them as join keys or GROUP BY columns

Using Frequency for Filter Values

Run mcp__qsv__qsv_frequency with select: "col", limit: 20 before writing WHERE clauses on categorical columns:

  • Pick selective filters: If frequency shows "active" has 90% of rows, filtering on WHERE status = 'active' is wasteful — filter on the rare values instead
  • Validate expected values: If you plan WHERE category IN ('A','B','C'), check frequency first to confirm those values exist and see if you're missing any
  • Avoid GROUP BY on high-cardinality columns: If frequency shows thousands of unique values, GROUP BY will produce a huge result — add LIMIT or aggregate differently

SQL Syntax Guide

The sqlp command uses Polars SQL dialect:

-- Basic select
SELECT col1, col2 FROM data WHERE col1 > 100

-- Aggregation
SELECT category, COUNT(*) as cnt, AVG(price) as avg_price
FROM data GROUP BY category ORDER BY cnt DESC

-- Window functions
SELECT *, ROW_NUMBER() OVER (PARTITION BY dept ORDER BY salary DESC) as rank
FROM employees

-- String operations
SELECT * FROM data WHERE col1 LIKE '%pattern%'

-- Date operations
SELECT *, EXTRACT(YEAR FROM date_col) as year FROM data

-- Multiple files (join)
SELECT a.*, b.name FROM file1 a JOIN file2 b ON a.id = b.id

-- CASE expressions
SELECT *, CASE WHEN amount > 1000 THEN 'high' ELSE 'low' END as tier FROM data

Table Naming Convention

  • File: sales_2024.csv -> Table: sales_2024
  • File: my-data.csv -> Table: "my-data" (quote if contains special chars)
  • Multiple files: each file is a separate table

Notes

  • sqlp uses the Polars engine - some PostgreSQL-specific syntax may not be supported
  • For very complex queries that fail, suggest DuckDB as an alternative
  • The stats cache helps Polars choose optimal data types for columns
  • Results go to stdout by default; use --output file.csv for large result sets
  • Column names are case-sensitive in SQL queries
  • Use LIMIT to preview large result sets before running full queries
  • sqlp can query multiple CSV files in a single SQL statement (useful for joins)

版本历史

  1. skills-20261103210927-6c1b454 GitHub ↗
    原版更新说明

    Automated skills release from commit 6c1b4543cac1d45a80bf5904e4b69ac315117323

  2. skills-20260928190452-ff51758 GitHub ↗
    原版更新说明

    Automated skills release from commit ff51758b06b8249007116184096765d47bdb7505

  3. skills-20260924105536-d31110d GitHub ↗
    原版更新说明

    Automated skills release from commit d31110d62dc0bd00c22f1d6f6a630d1e702a0049

  4. skills-20260923085113-cea285e GitHub ↗
    原版更新说明

    Automated skills release from commit cea285ef0e4d6ec47cd2fd9fdbca03813a3363c7

  5. skills-20260922193956-97d7333 GitHub ↗
    原版更新说明

    Automated skills release from commit 97d7333d8200e5ac556c659c8669f3a83ba10866

此处仅展示最近 5 个版本。 在原站查看完整版本历史 ↗

当前收录版本

0.0.1

核对来源版本 ↗

安全与评测信息

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值92/100

亮点

  • 提供基于 Polars SQL 引擎对 CSV/TSV/Excel 文件运行 SQL 查询的能力,属于数据处理领域的高频刚需工具
  • 功能完整,包含决策树、详细步骤、统计信息利用、SQL 语法指南等,显著提升用户在处理结构化数据时的效率
触发精准90/100

亮点

  • description 明确描述了核心功能,frontmatter 中 argument-hint 提供了参数提示 '<file> [query>',触发词覆盖合理,边界清晰
结构规范95/100

亮点

  • 文档结构清晰,包含决策树、步骤划分、使用统计信息编写更好 SQL 的详细说明、SQL 语法指南、表命名约定等
  • 有端到端示例,frontmatter 完整,单文件未超过 500 行
执行可靠90/100

亮点

  • 工具来源明确(qsv 系列工具),参数使用正确
  • 覆盖了主要异常情况(如大文件处理建议、工作目录同步提示、复杂查询失败建议 DuckDB 替代等),不可逆操作有明确说明
证据可验 (前四项均值)92/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。

文档引用的域名或地址

这些地址可能用于文档链接或示例,不是已批准的联网清单。使用前核对实际目的地及发送的数据。

  • github.com

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。