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

映射替换

简单 04-expr 新列与条件表达式 mapreplacedefaultNone

把订单渠道 channel 翻译成中文,放进新列 channel_cn:

channel channel_cn
app 应用
web 网页
store 门店
  • 其他任何值都映射为 其他,包括 null、不在表里的值(如 phone)、大小写不同的值(如 App)和空字符串。
  • 原来的 channel 列保持不变。

输入

  • orders(order_id, customer_id, order_ts, status, channel)

输出

列为 order_id, channel, channel_cn,每个订单一行,行顺序不限。

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

orders shop/orders
#order_idint64customer_idint64order_tsdatetimestatusstringchannelstring
1 1001 39 2026-01-01 19:38:00 paid app
2 1002 16 2026-01-17 14:07:00 paid app
3 1003 4 2026-01-08 15:40:20 cancelled web
4 1004 2 2026-05-23 10:48:58 paid null
5 1005 12 2026-06-22 11:07:22 paid store
6 1006 17 2026-08-15 05:15:25 paid web
7 1007 9 2026-06-11 01:00:32 refunded store
8 1008 45 2026-09-19 20:47:10 paid web
9 1009 2 2025-10-05 04:53:38 paid app
10 1010 4 2026-02-19 01:39:54 paid app
11 1011 28 2026-03-05 03:04:45 refunded store
12 1012 2 2026-08-01 07:09:17 paid web
13 1013 26 2026-01-22 03:48:14 refunded store
14 1014 2 2026-02-09 01:41:41 paid app
15 1015 5 2026-08-03 19:49:04 refunded web
16 1016 26 2026-02-16 00:43:43 refunded app
17 1017 9 2025-12-06 04:48:57 pending app
18 1018 999 2026-05-19 12:13:43 paid store
19 1019 26 2026-02-05 15:02:26 paid store
20 1020 44 2025-11-24 11:19:00 cancelled web
显示前 20 行,共 200 行

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

#order_idInt64channelStringchannel_cnString
1 1001 app 应用
2 1002 app 应用
3 1003 web 网页
4 1004 null 其他
5 1005 store 门店
6 1006 web 网页
7 1007 store 门店
8 1008 web 网页
9 1009 app 应用
10 1010 app 应用
11 1011 store 门店
12 1012 web 网页
13 1013 store 门店
14 1014 app 应用
15 1015 web 网页
16 1016 app 应用
17 1017 app 应用
18 1018 store 门店
19 1019 store 门店
20 1020 web 网页
21 1021 app 应用
22 1022 app 应用
23 1023 web 网页
24 1024 null 其他
25 1025 web 网页
26 1026 web 网页
27 1027 web 网页
28 1028 app 应用
29 1029 web 网页
30 1030 store 门店
31 1031 app 应用
32 1032 web 网页
33 1033 store 门店
34 1034 app 应用
35 1035 null 其他
36 1036 app 应用
37 1037 store 门店
38 1038 store 门店
39 1039 web 网页
40 1040 web 网页
41 1041 app 应用
42 1042 web 网页
43 1043 store 门店
44 1044 store 门店
45 1045 web 网页
46 1046 web 网页
47 1047 app 应用
48 1048 app 应用
49 1049 app 应用
50 1050 null 其他
显示前 50 行,共 200 行