dask
它能做什么
Dask 是一个帮助你处理超大数据集的工具,这些数据集的体积超过了电脑的内存。它会把任务拆分成更小的部分,并利用多个处理器核心,甚至多台电脑来并行处理,从而加快速度。
适用场景
- ✓当你的数据比电脑的内存(RAM)还大时。
- ✓想加速使用 Pandas 或 NumPy 等库进行的计算时。
- ✓需要同时处理大量文件(比如 CSV、日志)时。
技能链接
https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/dask/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我有一个 50GB 的 CSV 文件,内存放不下,怎么用 Dask 来分析它?”
每周 5 个新技能,1 分钟读完。
工作原理
Dask 会把你的数据切分成小块,并对这些小块并行地执行操作。它负责管理整个工作流程,确保即使数据太大无法一次处理,结果也能被正确地合并。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Dask
Overview
Dask is a Python library for parallel and distributed computing that enables three critical capabilities:
- Larger-than-memory execution on single machines for data exceeding available RAM
- Parallel processing for improved computational speed across multiple cores
- Distributed computation supporting terabyte-scale datasets across multiple machines
Capacity depends on partition sizes, intermediate data, concurrency, storage, and available memory.
Reviewed release: dask/distributed 2026.8.0 (September 30, 2026 review). Docs: docs.dask.org. Since 2025.1.0, the expression-based DataFrame API with query planning is the only implementation — do not install dask-expr separately or set dataframe.query-planning: False.
Quick Start
Installation
uv pip install "dask[array,dataframe]==2026.8.0"
For a typical pandas/NumPy workflow with the distributed scheduler and dashboard:
uv pip install "dask[complete]==2026.8.0"
Remote object storage (requires provider credentials for private data):
uv pip install s3fs # s3:// paths
uv pip install gcsfs # gs:// paths
Requires Python 3.10+, pandas 2+, PyArrow 16+. Zarr, HDF5, SciPy, Xarray, Dask-ML, and cluster deployment packages are separate optional dependencies. See review and validation for tested versions, source links, and limits. File paths and undefined application functions below are illustrative. Put process scheduler/Client() execution in a main() guarded by if __name__ == "__main__": in scripts; close clients and clusters afterward.
When to Use This Skill
This skill should be used when:
- Process datasets that exceed available RAM
- Scale pandas or NumPy operations to larger datasets
- Parallelize computations for performance improvements
- Process multiple files efficiently (CSVs, Parquet, JSON, text logs)
- Build custom parallel workflows with task dependencies
- Distribute workloads across multiple cores or machines
Core Capabilities
Dask provides five main components, each suited to different use cases:
1. DataFrames - Parallel Pandas Operations
Purpose: Scale pandas operations to larger datasets through parallel processing.
When to Use:
- Tabular data exceeds available RAM
- Need to process multiple CSV/Parquet files together
- Pandas operations are slow and need parallelization
- Scaling from pandas prototype to production
Reference Documentation: For comprehensive guidance on Dask DataFrames, refer to references/dataframes.md which includes:
- Reading data (single files, multiple files, glob patterns)
- Common operations (filtering, groupby, joins, aggregations)
- Custom operations with
map_partitions - Performance optimization tips
- Common patterns (ETL, time series, multi-file processing)
Quick Example:
import dask.dataframe as dd
# Read multiple files as single DataFrame
ddf = dd.read_csv('data/2024-*.csv')
# Operations are lazy until compute()
filtered = ddf[ddf['value'] > 100]
result = filtered.groupby('category')['value'].mean().compute()
Key Points:
- Operations are lazy (build task graph) until
.compute()called - Use
map_partitionsfor efficient custom operations - Convert to DataFrame early when working with structured data from other sources
2. Arrays - Parallel NumPy Operations
Purpose: Extend NumPy capabilities to datasets larger than memory using blocked algorithms.
When to Use:
- Arrays exceed available RAM
- NumPy operations need parallelization
- Working with scientific datasets (HDF5, Zarr, NetCDF)
- Need parallel linear algebra or array operations
Reference Documentation: For comprehensive guidance on Dask Arrays, refer to references/arrays.md which includes:
- Creating arrays (from NumPy, random, from disk)
- Chunking strategies and optimization
- Common operations (arithmetic, reductions, linear algebra)
- Custom operations with
map_blocks - Integration with HDF5, Zarr, and XArray
Quick Example:
import dask.array as da
# Small executable example; size chunks from uncompressed memory before scaling
x = da.random.default_rng(42).random((1000, 1000), chunks=(250, 250))
# Operations are lazy
y = x + 100
z = y.mean(axis=0)
# Compute result
result = z.compute()
Key Points:
- Chunk size is critical (aim for ~100 MiB per chunk, adjusted to memory and operation)
…
常见问题
什么是“块”(chunk)?
“块”是 Dask 为了处理数据而切分出来的小片段。
使用 Dask 一定需要多台电脑吗?
不一定。你可以在一台电脑上使用 Dask,既可以处理超出内存的数据,也可以把任务分配给处理器的多个核心,从而加快计算速度。
Dask 会取代 Pandas 和 NumPy 吗?
不会,Dask 是对 Pandas 和 NumPy 的扩展。它沿用你熟悉的语法,但能让你处理更大的数据,并且支持并行计算。
详情
作者的原始描述
Scales pandas, NumPy, and custom Python research workflows beyond memory or across clusters with Dask. Covers DataFrames, Arrays, Bags, Futures, chunking, schedulers, and distributed diagnostics. Use for partitioned file processing, scientific array computation, or parallel tasks whose memory and dependency structure require Dask.
热度
- GitHub 星标
- 51k
- 排名
- #3444
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …