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

selectors 批量变换

简单 23-polars-only Polars 专属 selectorsstandardizewindow

把行情表里除 volume 以外的所有数值列,在每只股票(ticker)内部做标准化(z-score):

新值 = (原值 − 该 ticker 该列的均值) / 该 ticker 该列的样本标准差

  • 样本标准差的分母是 n − 1;均值和标准差都忽略 null。
  • 原值为 null 的单元格结果仍为 null。
  • 某只股票只有一行时,标准差无定义,该股票的标准化结果全部为 null。
  • ticker、date、volume 原样保留;输出的行数与输入相同。

考点:用列选择器一次性选中“数值列但不含 volume”,不要逐列手写。判题只看结果。

输入

  • prices(ticker, date, open, high, low, close, volume)

输出

列为 ticker, date, open, high, low, close, volume,行顺序不限。

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

prices stocks/prices
#tickerstringdatedateopenfloat64highfloat64lowfloat64closefloat64volumeint64
1 AAPL 2026-06-01 189.58 190.97 188.93 190.66 7374313
2 AAPL 2026-06-02 191.71 195.6 191.42 194.12 1753601
3 AAPL 2026-06-03 194.95 196.13 193.04 193.67 2817746
4 AAPL 2026-06-04 194.03 194.88 187.39 189.08 2783341
5 AAPL 2026-06-05 189.72 193.66 189.02 193.14 8942829
6 AAPL 2026-06-08 192.9 193.62 188.21 188.64 1357786
7 AAPL 2026-06-09 188.63 189.8 185.9 188.98 5482117
8 AAPL 2026-06-10 189.78 191.79 188.78 191.45 1430484
9 AAPL 2026-06-11 191.12 193.18 190.85 192.68 7642427
10 AAPL 2026-06-12 191.04 193.87 190.02 193.37 2476587
11 AAPL 2026-06-15 193.53 195.45 193.24 193.68 1680820
12 AAPL 2026-06-16 194.69 195.53 192.04 193.09 4196575
13 AAPL 2026-06-17 192.64 196.25 191.03 195.73 1464728
14 AAPL 2026-06-18 195.19 196.94 192.23 192.74 2059908
15 AAPL 2026-06-19 192.02 196.01 191.78 195.55 8247165
16 AAPL 2026-06-22 195.28 196.64 188.45 null 2043265
17 AAPL 2026-06-23 190.64 191.82 190.11 191.55 2220638
18 AAPL 2026-06-24 192.95 193.43 189.2 190.21 2962146
19 AAPL 2026-06-25 190.43 190.7 188.71 189.26 1607246
20 AAPL 2026-06-26 189.15 189.58 188.4 189.15 4162289
显示前 20 行,共 296 行

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

#tickerStringdateDateopenFloat64highFloat64lowFloat64closeFloat64volumeInt64
1 AAPL 2026-06-01 0.134681529 0.06653338027 0.3932000219 0.3696287296 7374313
2 AAPL 2026-06-02 0.5681315266 0.9598621883 0.9236206383 1.048312026 1753601
3 AAPL 2026-06-03 1.227463917 1.062122289 1.26871357 0.960043967 2817746
4 AAPL 2026-06-04 1.040246078 0.8209428056 0.06514871695 0.0597097678 2783341
5 AAPL 2026-06-05 0.1631712002 0.5855516294 0.4123718514 0.8560838089 8942829
6 AAPL 2026-06-08 0.8102937318 0.5778338859 0.2398253858 -0.02659677853 1357786
7 AAPL 2026-06-09 -0.05864123989 -0.1592106166 -0.2522515716 0.04009464363 5482117
8 AAPL 2026-06-10 0.1753810593 0.2247471216 0.3612469727 0.5245882105 1430484
9 AAPL 2026-06-11 0.4480679122 0.4929387076 0.8021990514 0.7658542378 7642427
10 AAPL 2026-06-12 0.4317881001 0.6260697827 0.6253921793 0.9011985945 2476587
11 AAPL 2026-06-15 0.9384972522 0.9309206502 1.311317635 0.9620054794 1680820
12 AAPL 2026-06-16 1.174554528 0.9463561372 1.055693242 0.8462762469 4196575
13 AAPL 2026-06-17 0.7573843424 1.08527552 0.8405427105 1.364115525 1464728
14 AAPL 2026-06-18 1.276303354 1.218406595 1.096167104 0.7776233123 2059908
15 AAPL 2026-06-19 0.6312157985 1.038969059 1.000307956 1.328808301 8247165
16 AAPL 2026-06-22 1.294618142 1.160523519 0.2909502645 null 2043265
17 AAPL 2026-06-23 0.3503890395 0.2305354293 0.6445640088 0.5442033347 2220638
18 AAPL 2026-06-24 0.8204686144 0.5411746044 0.4507155104 0.2813606709 2962146
19 AAPL 2026-06-25 0.3076545327 0.01443861176 0.3463355498 0.0950169913 1607246
20 AAPL 2026-06-26 0.04717753886 -0.2016582057 0.2802992481 0.07344035472 4162289
21 AAPL 2026-06-29 -0.1827748073 0.2517592238 0.07792993662 0.4618198132 4111977
22 AAPL 2026-06-30 0.3544589925 0.1803700966 0.6317827891 0.2931297454 8190223
23 AAPL 2026-07-01 0.1407864585 0.2594769673 0.2653878252 0.5226266981 6480811
24 AAPL 2026-07-02 0.4989423251 0.2054527629 0.4677571367 0.2480149598 7408840
25 AAPL 2026-07-06 0.3117244857 -0.033797285 -0.2991160437 -0.4542064854 7304091
26 AAPL 2026-07-07 -0.1970196429 -0.1688577959 -0.3374597028 -0.4522449729 1584490
27 AAPL 2026-07-08 -0.8298973389 -0.8943256832 -0.7485889356 -0.7955096458 5473175
28 AAPL 2026-07-09 -0.6304696405 0.02987409873 -0.3374597028 0.253899497 6521527
29 AAPL 2026-07-10 0.277129885 0.1340636357 0.1546172547 0.002825907719 8236908
30 AAPL 2026-07-13 0.201835754 0.02794466286 0.4571061203 0.1558238762 8444728
31 AAPL 2026-07-14 0.1367165055 -0.05695051544 0.3995906317 0.2087847115 8134140
32 AAPL 2026-07-15 0.2669550024 0.8132250621 0.4145020547 1.0600811 6512712
33 AAPL 2026-07-16 0.842853356 0.9888037263 1.070604665 1.315077714 8228903
34 AAPL 2026-07-17 1.243743729 1.500104232 1.526468166 1.705418685 1010841
35 AAPL 2026-07-20 1.351597485 1.521328027 1.50942654 1.136580085 5287551
36 AAPL 2026-07-21 1.186764387 0.8826847535 0.6488244154 0.5657799713 7198556
37 AAPL 2026-07-22 0.3849836403 0.6125637316 0.546574658 0.7580081881 7967001
38 AAPL 2026-07-23 0.7818040606 0.4234790163 0.1205340022 -0.1854792843 1882074
39 AAPL 2026-07-24 -0.2010895959 -0.4582731765 -0.05627286995 -0.3718229639 3514237
40 AAPL 2026-07-27 -0.5470356034 -0.1148335916 -0.2671629946 0.0126334698 3476086
41 AAPL 2026-07-28 0.008512985085 0.03373297047 0.2462159957 0.2754761336 7620695
42 AAPL 2026-07-29 0.3381791804 0.6009871164 0.6679962449 0.9051216194 4745920
43 AAPL 2026-07-30 1.072805702 0.8730375741 0.6403036023 0.4127820028 6998221
44 AAPL 2026-07-31 0.4501028887 0.5122330663 0.59982974 0.8462762469 8463879
45 AAPL 2026-08-03 0.8184336378 1.010027521 0.4975799826 0.4735888877 5804973
46 AAPL 2026-08-04 0.7166848121 0.4620677337 0.3186429071 -0.02071224128 1627009
47 AAPL 2026-08-05 -0.5673853685 -0.7804889669 -0.6207767389 -0.8896622418 7679549
48 AAPL 2026-08-06 -1.088339356 -1.320731011 -1.002083126 -1.003429962 5471229
49 AAPL 2026-08-07 -1.074094521 -1.20882373 -0.8721407258 -0.9249694653 2142129
50 AAPL 2026-08-10 -1.029325037 -1.147081782 -0.8231460504 -1.052467772 2929009
显示前 50 行,共 296 行