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

list.eval 与 pl.element

中等 23-polars-only Polars 专属 listevalelementnested

清洗每篇文章的标签列表 tags:

  1. 去掉长度小于 3 个字符的标签(例如 ml、go);列表里为 null 的元素也去掉;
  2. 全部转成小写;
  3. 去重(转小写后相同的算重复);
  4. 按字母升序排列。

  5. tags 本身为 null 的文章,结果仍为 null;空列表,或者清洗后什么都不剩的,结果为空列表。

  6. 每篇文章一行,输出的列名仍叫 tags。

考点:在列表内部对每个元素求值,不要把列表炸开再收回。判题只看结果。

输入

  • articles(article_id, title, author, tags, published_at, word_count),tags 是字符串列表

输出

列为 article_id, tags,行顺序不限;tags 内部的元素顺序要符合上面的要求。

输入表 (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_idInt64tagsList(String)
1 1 ["etl", "python", "rust"]
2 2 ["sql"]
3 3 ["pandas"]
4 4 []
5 5 []
6 6 ["polars"]
7 7 ["rust"]
8 8 ["pandas", "python"]
9 9 ["etl"]
10 10 null
11 11 ["python", "viz"]
12 12 ["sql"]
13 13 ["pandas", "python"]
14 14 ["etl", "sql", "viz"]
15 15 ["polars", "sql"]
16 16 ["python", "rust"]
17 17 ["python"]
18 18 null
19 19 ["duckdb", "sql", "viz"]
20 20 ["duckdb", "python"]
21 21 ["python"]
22 22 ["etl", "polars", "rust"]
23 23 ["duckdb", "sql"]
24 24 ["duckdb"]
25 25 ["python", "viz"]
26 26 ["etl", "polars", "python", "sql"]
27 27 ["polars", "python", "rust", "sql"]
28 28 ["duckdb", "pandas"]
29 29 ["pandas"]
30 30 ["sql"]
31 31 []
32 32 ["python", "viz"]
33 33 []
34 34 ["pandas"]
35 35 ["duckdb"]
36 36 []
37 37 ["python"]
38 38 ["etl"]
39 39 ["duckdb"]
40 40 ["sql"]
共 40 行