我有一个查询列,其中的数据以逗号分隔。
读
1,2,3,2,4,3,4,5,2,1,3,4,5,2,1,3,4,2,1,2,3,4,2,1,2, 4,2,3,4,5
我想要一个脚本,将每个值解析为一个新列,列标题为 D01、D02、D03 等......
我已经使用了 Text to Cols 的插件来处理此列,但是如果有一个脚本作为生成这些列的查询后脚本的一部分,那就太好了
效果很好!谢谢。还要感谢您在脚本中的评论,他们将帮助我理解它并从中学习。
再次感谢!
实际上有一个文本到列()功能。这是一种使用表格来实现此操作的方法,其中我从 2 列(第 1 列和第 2 列)开始。因为 Text to Columns() 会在拆分列后直接插入新列,所以您需要确定列的位置,以便您可以轻松找到新列在表中的位置并对其进行重命名。
dt = Current Data Table();
col = "Column 1"; //name of column that needs to be split out
//Need to determine where new columns will go:
colnames = dt << Get Column Names(string);
which_col = Loc(colnames, col)[1]; //get position of column being split
//Get number of columns before split
n_col_pre = N Col(dt);
//Split the column by delimiter
dt << Text to Columns( delimiter(","),
columns(Column(dt, col))
);
//Determine number of new columns
new_cols = N Col(dt) - n_col_pre;
//Rename New Columns
for(i = 1, i <= new_cols, i++,
col_pos = which_col + i; //get position of current column
Column(dt, col_pos) << Set Name("D"||if(i < 10, "0","")||char(i));
Column(dt, col_pos) << Set Data Type(Numeric); //makes each column numeric, not sure if you needed that too
);
前:

后:
