我有一個查詢列,其中的數據以逗號分隔。
讀
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
);
前:

後:
