每個欄位如何排列?我有txt檔案。我想導入JMP進行分析。但有些列沒有對齊。我該如何排列它們?
分隔符號應該是空格、空格和逗號。但是“,”會將空格視為文字。我該如何克服這個問題?

dtTlog = Open(
D,
Import Settings(
End Of Line( CRLF, CR, LF ),
End Of Field( Spaces, Space, CSV( 1 ), Comma ),
Strip Quotes( 1 ),
Use Apostrophe as Quotation Mark( 0 ),
Use Regional Settings( 0 ),
Scan Whole File( 1 ),
Treat empty columns as numeric( 0 ),
CompressNumericColumns( 0 ),
CompressCharacterColumns( 0 ),
CompressAllowListCheck( 0 ),
Labels( 1 ),
Column Names Start( 1 ),
Data Starts( 2 ),
Lines To Read( "All" ),
Year Rule( "20xx" )
)
);
自動化和腳本編寫視窗回覆:如何排列每個欄位?您遇到的問題是您使用空格和逗號作為分隔符,並且在 f 列中,您的行同時具有逗號和空格分隔符。一個例子是
4, 7
列C1c 讀入4,然後將, 作為分隔符,後跟空格作為第二個分隔符,因此由於它在第一個分隔符和第二個分隔符之後沒有看到值,因此它將缺失值應用於列 f ,然後 7 就成為 C2c 列的值。
下面是一個腳本,它讀入所有數據,刪除所有逗號,將其保存到臨時區域,然後使用輸入流將其讀回
names default to here(1);
d= "<YOUR path="" and="" file="" name="">";
dt = Open(
D ,
columns( New Column( "c000001", Character, "Nominal" ) ),
Import Settings(
End Of Line( CRLF, CR, LF ),
End Of Field( CSV( 0 ) ),
Treat Leading Zeros as Character( 1 ),
Strip Quotes( 1 ),
Use Apostrophe as Quotation Mark( 0 ),
Use Regional Settings( 0 ),
Scan Whole File( 1 ),
Treat empty columns as numeric( 0 ),
CompressNumericColumns( 0 ),
CompressCharacterColumns( 0 ),
CompressAllowListCheck( 0 ),
Labels( 0 ),
Column Names Start( 0 ),
First Named Column( 0 ),
Data Starts( 1 ),
Lines To Read( "All" ),
Year Rule( "20xx" )
)
);
for each row(:c000001 = Trim(substitute(:c000001,","," ")));
dt << save ("$TEMP\interium file.txt");
dtTlog = Open(
"$TEMP\interium file.txt",
Import Settings(
End Of Line( CRLF, CR, LF ),
End Of Field( Spaces, Space, CSV( 1 ), Comma ),
Strip Quotes( 1 ),
Use Apostrophe as Quotation Mark( 0 ),
Use Regional Settings( 0 ),
Scan Whole File( 1 ),
Treat empty columns as numeric( 0 ),
CompressNumericColumns( 0 ),
CompressCharacterColumns( 0 ),
CompressAllowListCheck( 0 ),
Labels( 1 ),
Column Names Start( 2 ),
Data Starts( 3 ),
Lines To Read( "All" ),
Year Rule( "20xx" )
)
); </YOUR>

回覆:如何排列每個欄位?
好吧,我明白了。我理解你的建議。但它給了我以上的警覺。
回覆:如何排列每個欄位? For Each( {col},
dt << Get Column Reference( dt << Get Column Names( Character ) ),
If( !Is Empty( col << Get Formula ),
Continue()
);
For Each Row( dt, col[] = Substitute( col[], ",", " ", <<IGNORECASE></IGNORECASE>I replace that line with these code. It's working now. Thanks.
回覆:如何排列每個欄位?我的原始程式碼有一個小錯誤。我已經回去改正了。請複製它並驗證它是否有效。您所做的修復很好,但是,原始程式碼不會在每一列中單獨讀取。它將每一行中的所有資料作為一列讀入,然後從只有一列的資料表的角度進行處理。
回覆:如何排列每個欄位?或者,可以使用「載入文字檔案」將檔案作為文字打開,透過替換刪除逗號,最後將文字開啟到資料表中
原帖:
.csv 匯入錯誤/ @Craige_Hales
文件導入:指定NAN? / @jthi
txtfile = Load Text File("$DOWNLOADS/log - question2.txt");
substituteinto(txtfile,","," ");
Open(
Char to Blob(txtfile),
Import Settings(
End Of Field( Spaces, Space ),
)
);
回覆:如何排列每個欄位?文字到列:正確處理遺失的數據
「正確」?
對於您的任務,文字到列就像一個魅力:
dt = Open(
"$DOWNLOADS/log - question2.txt",
Import Settings(
End Of Field( Tab ),
Labels( 0 )
)
);
// split columns via Text to columns
dt << Text to Columns( columns( :c000001 ), Delimiters( " ", "," ));
dt << Delete Columns( :c000001);
// Move column names up
dt << Move up;