df-drills pandas · Polars · DuckDB SQL · DuckDB Relational 题目列表 登录

列表长度与包含

中等 18-nested 列表与结构体 listlengthcontainscase-insensitive

为每篇文章计算两列:

  • n_tags:tags 列表的元素个数(整数),重复的标签照样计数;null 列表算 0,空列表也是 0。
  • has_python:列表里是否有一个标签整个等于 python,不区分大小写(Python、PYTHON 都算;pythonic 不算)。null 列表和空列表为 false。

每篇文章一行。

输入

  • articles(article_id, title, author, tags, published_at, word_count):tags 是字符串列表,可能为空列表或 null

输出

列为 article_id, n_tags, has_python,has_python 为布尔值,行顺序不限。

输入表 (case base,共 2 个 case:base、edge)

articles blog/articles
#article_idint64titlestringauthorstruct<name: string, country: string>tagslist<string>published_atdatetimeword_countint64
1 1 A gentle intro to DuckDB {"name": "Hans Muller", "country": "DE"} ["etl", "Python", "rust"] 2026-02-07 18:20:00 353
2 2 Testing Python {"name": "Bob Smith", "country": "US"} ["SQL"] 2026-09-02 17:13:00 3726
3 3 10 tips for dataframes {"name": "Bob Smith", "country": "US"} ["pandas"] 2026-07-23 20:39:00 362
4 4 Debugging DuckDB {"name": "Amy Chen", "country": "US"} [] 2026-01-20 22:03:00 3845
5 5 Debugging window functions {"name": "Ana Souza", "country": "BR"} [] 2026-08-20 10:17:00 3899
6 6 Getting started with Polars {"name": "王芳", "country": "CN"} ["polars"] 2026-05-17 19:28:00 2086
7 7 Testing dataframes {"name": "Ana Souza", "country": "BR"} ["rust", "ml", "go"] 2026-08-01 17:58:00 1251
8 8 Benchmarking pandas {"name": "王芳", "country": "CN"} ["Python", "pandas", "ml", "go"] 2026-02-27 20:10:00 2984
9 9 Benchmarking Python {"name": "Hans Muller", "country": "DE"} ["etl"] 2026-09-09 09:30:00 1709
10 10 10 tips for dataframes {"name": "Amy Chen", "country": "US"} null 2026-08-11 21:07:00 2000
11 11 Debugging pandas {"name": "Amy Chen", "country": "US"} ["python", "viz"] 2026-06-23 17:24:00 3908
12 12 Getting started with SQL {"name": "Ana Souza", "country": "BR"} ["sql"] 2026-03-01 18:14:00 2493
13 13 Common pitfalls in SQL {"name": "Li Wei", "country": "CN"} ["python", "pandas", "python"] 2026-03-25 19:46:00 473
14 14 A gentle intro to ETL {"name": "王芳", "country": "CN"} ["viz", "SQL", "etl", "go"] 2026-07-21 18:59:00 3850
15 15 Common pitfalls in Python {"name": "Amy Chen", "country": "US"} ["SQL", "polars"] 2026-06-08 15:27:00 1357
16 16 Getting started with ETL {"name": "Ana Souza", "country": "BR"} ["rust", "ml", "python"] 2026-07-16 18:30:00 2713
17 17 A gentle intro to pandas {"name": "Kenji Sato", "country": "JP"} ["Python", "ml"] 2026-05-27 20:35:00 2305
18 18 Getting started with pandas {"name": "Li Wei", "country": "CN"} null 2026-06-17 11:01:00 1790
19 19 A gentle intro to ETL {"name": "Kenji Sato", "country": "JP"} ["duckdb", "SQL", "viz"] 2026-02-27 21:10:00 3630
20 20 Benchmarking DuckDB {"name": "Li Wei", "country": "CN"} ["Python", "duckdb"] 2026-05-07 13:35:00 1067
显示前 20 行,共 40 行

期望输出 (case base,行顺序不限)

#article_idInt64n_tagsInt64has_pythonBoolean
1 1 3 True
2 2 1 False
3 3 1 False
4 4 0 False
5 5 0 False
6 6 1 False
7 7 3 False
8 8 4 True
9 9 1 False
10 10 0 False
11 11 2 True
12 12 1 False
13 13 3 True
14 14 4 False
15 15 2 False
16 16 3 True
17 17 2 True
18 18 0 False
19 19 3 False
20 20 2 True
21 21 2 True
22 22 3 False
23 23 4 False
24 24 1 False
25 25 2 True
26 26 4 True
27 27 4 True
28 28 3 False
29 29 1 False
30 30 1 False
31 31 0 False
32 32 2 True
33 33 0 False
34 34 2 False
35 35 1 False
36 36 0 False
37 37 2 True
38 38 2 False
39 39 1 False
40 40 3 False
共 40 行