从文本文件导入数据的问题我们在从文本文件导入数据时遇到了问题。现在,某些列出现了错误信息(“导入列时遇到无效数据……请尝试重新导入数据,但请明确将这些列的数据类型设置为字符”)。
为了更好地说明,我们有一个 JMP 脚本,用于从数据库中提取大量数据。提取后,数据将根据每个数据实例的列和行中的参数进行组织。这些参数都是分类的,但也有很多是数值型的(很多是日期格式的)。几年前,我们寻求帮助,希望提高性能(时间),将所有列转换为合适的数据类型(由于列数数千,使用 JMP 脚本花费了大量时间)。
Jim Nelson 建议将表格保存为文本文件,然后再打开。这个方法效果很好,性能得到了显著提升,所有列都转换为数字格式,并且保留了日期格式。
现在,这不再起作用,并且窗口警报停止执行。
我查看了社区,尝试了一种建议的方法:
collist = dt << Get Column Names("String");
For Each({colname}, collist,
r = Column(dt, colname) << Set Data Type("Numeric", << Fail On Conversion Error, <
<RETURN failed="" rows=""></RETURN>
<P>这不太好,因为我们丢失了日期格式,所以应该是日期的列以数字格式出现。</P> <P>有人能建议一种解决方法吗?</P>
<LINGO-LABS id="lingo-labs-909378" slang="en-US" mode="CREATE">
<LINGO-LABEL>自动化和脚本</LINGO-LABEL>
</LINGO-LABS>
回复:从文本文件导入数据的问题什么变化导致该过程停止运行?
您使用的 JMP 是什么版本?
什么操作系统?
您能否提供您正在读取的文本文件的示例以及您用来执行此操作的 JSL?
回复:从文本文件导入数据的问题I'm using JMP PRO ver 18.0.0 (JMP normal show the same behavior).
Operating system : Windows 10 Enterprise
What I changed is the instruction open("C:\TEMP\jmp_conversion.csv", columns(LOT_ID=character), scan whole file(1));
where I added the clause columns(LOT_ID=character). Without this change it works (but in some specific case the lot_id is converted numeric in scientific notation: the reason for the change).
Consider that if you run just the following script you do not receive the blocking alert but a message in the log. (I don't know why)
numeric_conversion = function({dt},{Default Local},
n= dt << get name();
try(delete file("C:\TEMP\jmp_conversion.csv"));
dt << save as("C:\TEMP\jmp_conversion.csv");
close(dt,nosave);
try(
dt= open("C:\TEMP\jmp_conversion.csv", columns(LOT_ID=character), scan whole file(1));
);
dt << set name(n);
return(dt);
);
dt= data table("ExtractedData");
dt = dt << split(
split( :VALUE ),
split by( :PARAM ),
group( :LOT_ID, :WAFER_NO ),
remaining Columns( Keep All ),
);
dt = numeric_conversion(dt);
回复:从文本文件导入数据的问题脚本运行正常,JMP 也确实会告诉你日志消息的原因
Invalid data encountered while importing the column Reactor.
25 values were set to missing.
Try importing the data again, but explicitly set the Data Type of those columns to Character.
这是由于 Reactor 列中缺少字符值造成的。如果您想避免这种情况,可以将 Open 函数包装在 Log Capture() 函数中。
Names Default To Here(1);
numeric_conversion = Function({dt_split}, {Default Local},
n = dt_split << get name();
Try(Delete File("C:\TEMP\jmp_conversion.csv"));
dt_split << Save As("C:\TEMP\jmp_conversion.csv");
Close(dt_split, nosave);
Log Capture(dt_split = Open("C:\TEMP\jmp_conversion.csv", columns(LOT_ID = character), scan whole file(1)));
dt_split << set name(n);
Return(dt_split);
);
dt = Open("$DOWNLOADS/ExtractedData.jmp");
dt_split = dt << split(split(:VALUE), split by(:PARAM), group(:LOT_ID, :WAFER_NO), remaining Columns(Keep All), Output table("ExtractedData Split"));
Close(dt, no save);
dt_split = numeric_conversion(dt_split);