我们给出了两种示例方法,推荐第二种,实现简单、性能更好。
模拟数据:
t = table(2022.08.01 2022.08.02 2022.08.03 as date, `000001.SZ`000002.SZ`000003.SZ as windCode, `1101`1102`1103 as industryCode)
方案1:
res = select iif(isNull(industryCode), 0, 1) from t pivot by date, windCode, industryCode nullFill!(res, 0)
方案2:
oneHot(t, `industryCode)
第2种方案用的One Hot编码方式,关于One Hot编码详见:How can I one hot encode in Python?