Hub documentation
组合数据集并导出
单点登录(SSO) 审计日志 存储区域 用于私有数据集的 Data Studio 资源组(访问控制) 高级计算选项 高级安全 令牌管理 服务账号 发布者分析 门控组集合 网络安全 下载分析 速率限制 博客文章
PRO 计划 仓库 入门仓库 仓库设置 存储限制 存储后端(Xet) 本地缓存 Pull Requests 与 Discussions 通知 集合 Webhooks GitHub Actions Notebooks 后续步骤 许可证
模型 数据集 数据集概述 数据集卡片 受控数据集 上传数据集 上传数据集(用于 LLM) 下载数据集 流式数据集 集成库
Spaces Argilla Daft Dask 数据集 数据设计师 Distilabel DuckDB 嵌入图谱 fenic FiftyOne Lance Pandas Polars Spark WebDataset
Data Studio Agent 轨迹 数据集下载统计 Spaces 概览 Spaces GPU 升级 Spaces ZeroGPU Spaces 开发模式 Spaces 磁盘使用量与存储 Spaces 自定义域名 Spaces 作为 MCP 服务器 Spaces 作为智能体工具 将 Spaces 用作 API 端点 Gradio Spaces Streamlit Spaces 静态 HTML Spaces Docker Spaces 嵌入您的 Space 使用 Docker 运行 Spaces Spaces 配置参考 使用 HF 登录按钮 精选 Spaces Spaces 更新日志 高级主题
存储桶 new 容器镜像 new 任务 智能体 智能体概述 Hugging Face AI 智能体 CLI Hugging Face MCP 服务器 Hugging Face Agent Skills 使用 HF SDK 构建智能体 使用 llama.cpp 的本地代理 Agent 库 会话跟踪格式
其他 组合数据集并导出
在本节中,我们将演示如何合并两个数据集并导出结果。第一个数据集为 CSV 格式,第二个数据集为 Parquet 格式。让我们先查看一下我们的数据集:
第一个是 TheFusion21/PokemonCards:
FROM 'hf://datasets/TheFusion21/PokemonCards/train.csv' LIMIT 3;
┌─────────┬──────────────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬────────────┬───────┬─────────────────┐
│ id │ image_url │ caption │ name │ hp │ set_name │
│ varchar │ varchar │ varchar │ varchar │ int64 │ varchar │
├─────────┼──────────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼────────────┼───────┼─────────────────┤
│ pl3-1 │ https://images.pok… │ A Basic, SP Pokemon Card of type Darkness with the title Absol G and 70 HP of rarity Rare Holo from the set Supreme Victors. It has … │ Absol G │ 70 │ Supreme Victors │
│ ex12-1 │ https://images.pok… │ A Stage 1 Pokemon Card of type Colorless with the title Aerodactyl and 70 HP of rarity Rare Holo evolved from Mysterious Fossil from … │ Aerodactyl │ 70 │ Legend Maker │
│ xy5-1 │ https://images.pok… │ A Basic Pokemon Card of type Grass with the title Weedle and 50 HP of rarity Common from the set Primal Clash and the flavor text: It… │ Weedle │ 50 │ Primal Clash │
└─────────┴──────────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴────────────┴───────┴─────────────────┘第二个将是 wanghaofan/pokemon-wiki-captions:
FROM 'hf://datasets/wanghaofan/pokemon-wiki-captions/data/*.parquet' LIMIT 3;
┌──────────────────────┬───────────┬──────────┬──────────────────────────────────────────────────────────────┬────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ image │ name_en │ name_zh │ text_en │ text_zh │
│ struct(bytes blob,… │ varchar │ varchar │ varchar │ varchar │
├──────────────────────┼───────────┼──────────┼──────────────────────────────────────────────────────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ {'bytes': \x89PNG\… │ abomasnow │ 暴雪王 │ Grass attributes,Blizzard King standing on two feet, with … │ 草属性,双脚站立的暴雪王,全身白色的绒毛,淡紫色的眼睛,几缕长条装的毛皮盖着它的嘴巴 │
│ {'bytes': \x89PNG\… │ abra │ 凯西 │ Super power attributes, the whole body is yellow, the head… │ 超能力属性,通体黄色,头部外形类似狐狸,尖尖鼻子,手和脚上都有三个指头,长尾巴末端带着一个褐色圆环 │
│ {'bytes': \x89PNG\… │ absol │ 阿勃梭鲁 │ Evil attribute, with white hair, blue-gray part without ha… │ 恶属性,有白色毛发,没毛发的部分是蓝灰色,头右边类似弓的角,红色眼睛 │
└──────────────────────┴───────────┴──────────┴──────────────────────────────────────────────────────────────┴────────────────────────────────────────────────────────────────────────────────────────────────────┘
现在,让我们尝试通过连接 name 列来合并这两个数据集:
SELECT a.image_url
, a.caption AS card_caption
, a.name
, a.hp
, b.text_en as wiki_caption
FROM 'hf://datasets/TheFusion21/PokemonCards/train.csv' a
JOIN 'hf://datasets/wanghaofan/pokemon-wiki-captions/data/*.parquet' b
ON LOWER(a.name) = b.name_en
LIMIT 3;
┌──────────────────────┬──────────────────────┬────────────┬───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ image_url │ card_caption │ name │ hp │ wiki_caption │
│ varchar │ varchar │ varchar │ int64 │ varchar │
├──────────────────────┼──────────────────────┼────────────┼───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ https://images.pok… │ A Stage 1 Pokemon … │ Aerodactyl │ 70 │ A Pokémon with rock attributes, gray body, blue pupils, purple inner wings, two sharp claws on the wings, jagged teeth, and an arrow-like … │
│ https://images.pok… │ A Basic Pokemon Ca… │ Weedle │ 50 │ Insect-like, caterpillar-like in appearance, with a khaki-yellow body, seven pairs of pink gastropods, a pink nose, a sharp poisonous need… │
│ https://images.pok… │ A Basic Pokemon Ca… │ Caterpie │ 50 │ Insect attributes, caterpillar appearance, green back, white abdomen, Y-shaped red antennae on the head, yellow spindle-shaped tail, two p… │
└──────────────────────┴──────────────────────┴────────────┴───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
我们可以使用 COPY 命令将结果导出到 Parquet 文件中:
COPY (SELECT a.image_url
, a.caption AS card_caption
, a.name
, a.hp
, b.text_en as wiki_caption
FROM 'hf://datasets/TheFusion21/PokemonCards/train.csv' a
JOIN 'hf://datasets/wanghaofan/pokemon-wiki-captions/data/*.parquet' b
ON LOWER(a.name) = b.name_en)
TO 'output.parquet' (FORMAT PARQUET);让我们验证新的 Parquet 文件:
SELECT COUNT(*) FROM 'output.parquet';
┌──────────────┐
│ count_star() │
│ int64 │
├──────────────┤
│ 9460 │
└──────────────┘
最后,让我们将生成的数据集推送到 Hub。你可以使用 Hub UI、huggingface_hub 客户端库等工具来上传你的 Parquet 文件,更多信息请参见此处。
就是这样!你已成功合并了两个数据集,导出了结果,并将其上传到了 Hugging Face Hub。
Update on GitHub