dolphindb中矩阵如何转化为按行、列和值组成的三列数据的表

            sh600000 sh600002 sh600003
           -------- -------- --------
2022.10.18|1                         
2022.10.19|         2                
2022.10.20|                  3      

如上的矩阵,如何转化为如下的表

date       code     Price
---------- -------- -----
2022.10.18 sh600000 1    
2022.10.19 sh600000      
2022.10.20 sh600000      
2022.10.18 sh600002      
2022.10.19 sh600002 2    
2022.10.20 sh600002      
2022.10.18 sh600003      
2022.10.19 sh600003      
2022.10.20 sh600003 3
请先 登录 后评论

1 个回答

mhxiang

矩阵转化为表时会丢失行标签。先通过join把行标签连接起来,再用unpivot

  t = table(2022.10.18 2022.10.19 2022.10.20 as Date, `sh600000`sh600002`sh600003 as Code, 1.0 2.0 3.0 as Price)
m = exec Price from t pivot by Date, Code

t=table(m.rowNames() as date) join table(m)
t=t.unpivot(`date, m.colNames()).rename!(`date`code`Price)
t
date       code     Price
---------- -------- -----
2022.10.18 sh600000 1    
2022.10.19 sh600000      
2022.10.20 sh600000      
2022.10.18 sh600002      
2022.10.19 sh600002 2    
2022.10.20 sh600002      
2022.10.18 sh600003      
2022.10.19 sh600003      
2022.10.20 sh600003 3
请先 登录 后评论