從 Txt 文件格式化數字數據的問題親愛的社區,
我正在嘗試構建一個 jsl 腳本來正確導入 ecnlosed 示例文件中格式化的數據。 我面臨的挑戰:
- 十進制符號是“,”而不是“.”。 通過使用我的區域首選項的默認設置,JMP 將“,”解釋為千位分隔符。 如何強制 JMP 在 jsl 腳本中正確解釋這些數字?
- 負數的格式如下:64,000-。 JMP 可以處理這種格式嗎?
一種解決方案可能是重新格式化 txt 文件,但它是從 ERP 中提取的,IT 團隊不明白我無法像 Excel 那樣處理此類文件。
感謝致敬,
熱羅姆
腳本編寫回复:從 Txt 文件格式化數字數據的問題你好,
您可以嘗試以下操作;當您提到 IT 不了解您的問題時,您可以使用 JSL 自己重新格式化文件。 雖然可能有一個導入設置來處理逗號作為小數,但我無法立即想到它,也無法在文檔中找到它。 也許其他人會用該設置回复。 在那之前,看看這是否有效。 我附上了一個示例文件;如果你把它放在你的下載文件夾中,腳本有望無需修改就可以運行。
</CODE></P>
<PRE><CODE class=" language-jsl">Names Default To Here( 1 );
//set these to reflect your path and file name
path = "$DOWNLOADS/";
origFile = "example.txt";
holdFile = "example_modified.txt";
//get text of original file and replace commas with decimals
txt = Substitute( Load Text File( path || origFile ), ",", "." );
//save resulting text to a file, open this file as a table, then delete the file
Save Text File( path || holdFile, txt );
dt = Open( path || holdFile );
Delete File( path || holdFile );
//create a new column. if the last character is not "-", the string is immediately converted to a number. If the last
//character IS a "-", the string is converted to a number after the "-" is moved to the first character of the string
dt << New Column( "xx", formula( Num( If( Right( :INFO, 1 ) != "-", :INFO, "-" || Left( :INFO, Length( :INFO ) - 1 ) ) ) ) );
//remove the formula, so we can delete the original INFO column and rename our new column to INFO
dt:xx << Delete Formula;
dt << Delete Columns( "INFO" );
dt:xx << set name( "INFO" );
乾杯,
布雷迪
回复:從 Txt 文件格式化數字數據的問題我喜歡這個聰明的解決方案,我不知道這種直接修改txt文件的方式。 非常感謝你!