根据单独 .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 );
);