Txt 檔案中的數字資料格式問題親愛的社區,
我正在嘗試建立一個 jsl 腳本來正確導入 ecnlosed 範例文件中格式的資料。我面臨的挑戰:
- 小數點符號是“,”而不是“.”。透過使用我的區域首選項的預設設置,JMP 將“,”解釋為千位分隔符號。如何強制 JMP 在 jsl 腳本中正確解釋這些數字?
- 負數的格式如下:64,000-。 JMP可以處理這種格式嗎?
一種解決方案可能是重新格式化 txt 文件,但它是從 ERP 中摘錄的,IT 團隊不明白我無法像 Excel 那樣處理此類文件。
謝謝和問候,
傑羅姆
自動化和腳本編寫大規模客製化回复:從 Txt 文件格式化數字數據的問題我喜歡這個聰明的解決方案,我不知道這種直接修改 txt 文件的方法。 非常感謝!
回复:從 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" );
乾杯,
布雷迪