根據單獨 .csv 文件中行中的值重命名 jmp 文件中的列名稱你好,
我是 JSL 的新手,非常感謝幫助。
我有三個文件。
文件 #1:它是參考文件,[as ref.csv] 包含 3 列,如下所示。
類別、寬度、標籤
--------------------------------
A,0,L1.abc
A,1,L2.xt
A,2,L8.dr
A,3,L20.ws
A,4,L72.oz
B,0,L11.qq
....
B,6,L61.er
文件#2:JMP 中的數據文件#1,包含類別、數據和許多其他列。
文件#3:JMP 中的數據文件#2,包含類別、數據和許多其他列。
兩個數據文件[文件#2 和文件#3] 之間的區別在於數據列中值的類別類型和寬度。
數據文件#1:
類別|數據|多列......
----------------------------------------------------
123.23....
321.45 ....
……
許多行
“數據”列中值的寬度[不包括點]與給定類別的文件 #1 中的行數匹配
例子:
數據文件#1 中第 1 行 123.23 的寬度為 5。
類別 A 的參考文件中的行數將為 5。這不需要按說法進行測試。這就是表格的進來方式[即從源中提取時]
將來,在參考文件中,例如對於類別 A,行數增加到 6 或更多,當從數據庫中提取信息時,文件數據文件 #1 中的數據列中保存的值的寬度也會增加。
數據文件#2:
類別|數據|多列......
----------------------------------------------------
B 1236.23 ....
B 3213.45 ....
……
許多行
目標 1:根據數據文件 #1 [和其他數據文件] 中“數據”列中保存的值的寬度創建新列
我的目標#1 已經完成了!
前任:
更新後的數據文件#1 如下所示:
類別|數據|c1|c2|c3|c4|c5|許多列.....
----------------------------------------------------
123.23 1 2 3 2 3 ....
321.45 3 2 1 4 5 ....
……
目標 2:將數據文件 #1 中的新列重命名為 L1... 到 L72...,如參考文件中“標籤”列中所定義。單元格值沒有變化,只需更新選定的列名稱。
目標 2 完成後的預期輸出:
更新數據文件#1,如下所示:
類別|數據|L1.abc|L2.xt|L8.dr|L20.ws|L72.oz|許多列.....
----------------------------------------------------
123.23 1 2 3 2 3 ....
321.45 3 2 1 4 5 ....
……
我需要幫助實現目標#2。
對於目標#2,我打開了參考文件,但不確定是否繼續前進。
謝謝
大衛
數據存取大規模定制回复:根據單獨的 .csv 文件中的行中的值重命名 jmp 文件中的列名稱好吧......這有點挑剔......但是dataTablesList中的不是數據表名稱列表,而是data table()函數,它指向數據表。
{"Table1","Table2"} // 數據表名稱列表
{ data table( "Table1" ), data table( "Table2" ) } // 指向數據表的指針列表回复:根據單獨的 .csv 文件中的行中的值重命名 jmp 文件中的列名稱是的。知道了。保存數據表的名稱
-大衛
回复:根據單獨的 .csv 文件中的行中的值重命名 jmp 文件中的列名稱dataTableList不保存數據表,它只保存指向表的指針。 創建列表然後運行
Show( dataTableList );
您將看到列表中的內容。
您還可以通過將鼠標懸停在變量上來查看列表中的內容,它將顯示其值
回复:根據單獨的 .csv 文件中的行中的值重命名 jmp 文件中的列名稱謝謝吉姆。 [根據我的需要]稍加改動就可以了! 謝謝 !!
問題,列表 [datatableList] 可以容納大量信息嗎?
我的每個表都有很多行(例如數千行),並且也有很多列。
-大衛
回复:根據單獨的 .csv 文件中的行中的值重命名 jmp 文件中的列名稱抱歉我的錯誤信息。我誤讀了類別數據表的結構。下面的腳本創建了幾個數據表和一個類別表,然後擴展數據表,最後根據類別數據表中的條目重命名列。我希望這能讓我們重回正軌。該腳本將根據需要處理盡可能多的數據表。所要做的就是將所有要處理的數據表添加到dataTableList列表中
Names Default To Here( 1 );
// This example script opens up 2 data tables and 1 category table.
// In reality, as many as necessary data tables could be used
// Create the tables
dt1 = New Table( "Table1",
Add Rows( 3 ),
New Column( "Category", Character, "Nominal", Set Values( {"ABC", "ABC", "ABC"} ) ),
New Column( "DATA", Character( 33 ), "Nominal", Set Values( {"123.56.8.342", "431.02.0.567", "318.00.1.816"} ), Set Display Width( 182 ) )
);
dt2 = New Table( "Table2",
Add Rows( 3 ),
New Column( "Category", Character, "Nominal", Set Values( {"B", "B", "B"} ) ),
New Column( "Data", Character, "Nominal", Set Values( {"13.24", "98.44", "63.89"} ) )
);
dtCat = New Table( "The Categories",
Add Rows( 13 ),
New Column( "Category",
Character,
"Nominal",
Set Values( {"ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "B", "B", "B", "B"} ),
Set Display Width( 67 )
),
New Column( "Width", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3] ) ),
New Column( "Label",
Character( 16 ),
"Nominal",
Set Values(
{"label0.0", "label0.1", "label0.2", "label0.3", "label0.4", "label0.5", "label0.6", "label0.7", "label0.8", "thelabel.1", "thelabel.2",
"thelabel.3", "thelabel.4"}
),
Set Display Width( 99 )
)
);
// Below this line, is the script that will add the new columns to each of the data tables
// and will take the names from the dtCat (Categories) data table and change the names to
// the columns in each of the data tables
// Create a list of the pointers to the data tables. This will allow for the using of the list
// entries to point to the data tables using a subscript
dataTableList = {};
insert into(dataTableList, dt1 );
insert into(dataTableList, dt2 );
// Loop across the data table list and expand the columns based upon the the column called Data
For( i = 1, i <= N Items( dataTableList ), i++,
ncols_to_add = length( substitute((dataTableList[i]:Data)[1],".",""));
For( k = 1, k <= ncols_to_add, k++, // the || operator joins two strings
dataTableList[i] << New Column( "c" || Char( i ),
Numeric,
Continous,
<<SET each="" value=""></SET>回复:根據單獨的 .csv 文件中的行中的值重命名 jmp 文件中的列名稱吉姆,
對於步驟 2 進行以下修改 [如下所示]
++++
這是我的 ref.csv :
類別|寬度|標籤
ABC 0 標籤0.0
ABC 1 標籤0.1
ABC 2 標籤0.2
ABC 3 標籤0.3
ABC 4 標籤0.4
ABC 5標籤0.5
ABC 6 標籤0.6
ABC 7 標籤0.7
ABC 8標籤0.8
ABC 9 標籤0.9
ABC 10 標籤0.10
ABC 11 標籤0.11
ABC 12 標籤0.12
ABC 13 標籤0.13
ABC 14 標籤0.14
ABC 15 標籤1.15
ABC 16 標籤0.16
ABC 17 標籤0.17
ABC 18 標籤0.18
ABC 19 標籤0.19
ABC 20標籤0.20
B 0 標籤11.22
C 1 標籤11.21
D 2 標籤11.23
E 0 標籤11.24
我的代碼:
dt_ref = 打開(“ref.csv”);
For( i=1, i<= N 行( dt_ref ), i++,
插入(Category_List, word(1,:label[i],".") || “。” ||字(2,:標籤[i], "." ) );
);
顯示(類別列表);
+++
我在日誌中收到以下內容:
Category_List = {“label0.0”,“label0.1”,“label0.2”,“label0.3”,“label0.4”,“label0.5”,“label0.6”,“label0.7” 、“標籤0.8”、“標籤0.9”、“標籤0.10”、“標籤0.11”、“標籤0.12”、“標籤0.13”、“標籤0.14”、“標籤1.15”、“標籤0.16”、“標籤0.17”、“標籤0.18”、“標籤0.19”、“標籤0.20”、“標籤11.22”、“標籤11.21”、“標籤11.23”、“標籤11。 24", ".", "."};
我希望它僅在類別為 ABC 時選擇標籤。我怎麼做?
我嘗試了以下操作,但 Category_List 沒有返回任何內容:
prod_found ={“ABC”};
if (:產品 == prod_found,
For( i=1, i<= N 行( dt_ref ), i++,
插入(Category_List, word(1,:name[i],".") || “。” ||字(2,:名稱[i], "." ) );
);
);
謝謝,
大衛
回复:根據單獨的 .csv 文件中的行中的值重命名 jmp 文件中的列名稱我看了你提供的代碼.. 似乎有些混亂。
這是我攔截並糾正我錯誤的方式。
dtcat 是列名稱為 [ 的引用表類別、寬度、標籤]。
有多個數據表 dt1,dt2 等具有相同的結構和列名稱 [類別|數據|許多列.....]
當我運行代碼時,它什麼也沒做
dtcat 表中沒有名為 data 的列,並查看了調試。
可能您的意思是 dt1 表,因為它是數據列。
我試著玩玩,但沒有幫助。
我認為我們在表格上的定義是一致的,使用我在原始帖子中描述的內容,我認為可能會有所幫助。
再次感謝這裡的幫助。
讓我推薦第 2 步
謝謝
大衛
回复:根據單獨的 .csv 文件中的行中的值重命名 jmp 文件中的列名稱- 你表明我的最後一個代碼不起作用......為什麼不呢?
- 這是創建您要求的列表的方法
Category_List = {};
For( i=1, i<= N Rows( dtCat ), i++,
insert into(Category_List, word(3,:data[i],".") || "." || word(4,:data[i], "." ) );
);
回复:根據單獨的 .csv 文件中的行中的值重命名 jmp 文件中的列名稱謝謝吉姆。它不起作用。
因此,對於目標#2,我將整個邏輯分解為值步驟。
步驟1:從數據表中獲取類別名稱[比如說dt1]並將其存儲在變量中[比如說它保存著A的類別]-完成
步驟2:從步驟1讀取變量並找到與category = A匹配的所有行]從ref.csv的“Label”列中獲取標籤名稱,[您將其稱為dtCat],並將其存儲在列表或變量中。 [說它叫category_list]
因此使用討論中所述的示例。 我期望category_list 保持低於值。
類別列表 = L1.abc, L2.xt, L8.博士, L20.ws, L72.oz
我不知道該怎麼做。 感謝幫助。
步驟 3:檢查 list == no 中的計數。在 dt1 中創建的新列數。這是我為了穩健性而做的額外事情。
category_list 中的計數為 5 個元素
dt1 中創建的新列是 5。 [我從目標 1 得到這個,因為我持有一個變量來查找需要多少個新列]。
步驟 4:使用循環替換 dt1 中的列名稱,即 c[i] 為 list [i],其中 i = 5
c1被替換
我現在處於第 2 步,需要一些幫助。
謝謝,
大衛
回复:根據單獨的 .csv 文件中的行中的值重命名 jmp 文件中的列名稱這是一個未經測試的腳本,應該非常接近能夠實現您的第二個目標
dtCat = Data Table( "file#1 name" );
dt1 = Data Table( "file#2 name" );
dt2 = Data Table( " file#3 name" );
// add dt3, dt4 etc. for each of the categories you have
// Find the number of data tables to process....A B C......
// Create a temporary new column in data table dtCat that has just the category
dtCat << New Column( "temp", character, formula( Word( 1, :data, "." ) ) );
// Summarize the data getting one element in the ByGroup list for each Category found
Summarize( dt, Categories = ByGroup( :temp ) );
numCategories = N Items( Categories );
For( i = 1, i <= numCategories, i++,
// Subset the dtCat table into the a new data table with just the one
// category being processed
dtCat << select where( :temp == Categories[i] );
dtSub = dtCat << subset( selected rows == 1, selected columns( 0 ) );
// set the offset of where to start the renaming
offset = 3;
// Loop
// Change names in dt1 to match the Label in
For( k = 1, k <= N Rows( dtSub ), k++,
Eval(
Substitute(
Expr(
Column( __dt__, k + offset ) << set name( Word( 3, dtSub:Data[k], "." ) ),
Expr( __dt__ ),
Parse( "dt" || Char( i ) )
)
)
)
);
Close( dtSub, nosave );
);