Web ページからダウンロードした txt ファイル、このファイルにはデータが含まれています。JSL を使用してこのような txt ファイルを表形式データとして処理するにはどうすればよいですか?
JSON では処理できません。専門家に感謝します。

// the U.txt file has 2 extra characters at the
// start and 3 extra characters at the end.
// visual inspection is the only way I know to
// figure that out.
// using JMP 15's json wizard
x = Load Text File( "E:/U.txt" );
x = Substr( x, 3, Length( x ) - 5 );
Open( Char To Blob( x ), jsonwizard( 0 ) );
// using JMP 14's basic json support
x = Load Text File( "E:/U.txt" );
x = Substr( x, 3, Length( x ) - 5 );
Open( Char To Blob( x ), "json" );
JMP 15 を使用している場合は、ウィザードを対話的に使用することもできます (GUI を表示するには、JsonWizard(1) を使用します)。余分な文字を削除するにはまだ助けが必要です。上記の JSL は、txt を x にロードし、substr() で 2 文字と 3 文字を削除してから、ディスクに再書き込みせずに、BLOB を介してデータを open() に渡します。 ディスクに書き換える場合は、拡張子を .json に変更することもできます。
JMP 15's wizard also guesses the datatypes better in this exampleJMP 15's wizard also guesses the datatypes better in this exampleこの例では、JMP 15 のウィザードもデータ型をより正確に推測します。
@デビッドバーバー
いいえ、その通りです。 私は自分のアプローチに基づいて 2 時間を費やしてスクリプトを作成しましたが、多くの退屈な問題に遭遇しました。 今はもう時間がありません。
lwx228 さん、こんにちは。
以下に、データをインポートし、適切に再コーディングし、テキストを列に配置し、スタックし、分割して最終的なテーブルを取得するスクリプトを示します。
これは非常に奇妙なデータ形式であるため、次のようなコメントがあります。
- 通常の txt ファイルと比較すると、区切り文字に矛盾があります。
- カンマはフィールド内および区切り文字として使用されます。
- 引用符も使用されますが、要素ごとに使用されるわけではありません。
- 括弧はいくつかの方法で使用されます
- 欠損値に対して「null」ステートメントが存在する場合もありますが、存在しない場合もあります。
- 列名の最初の行はなく、データ フィールド内にあります。 そのため、分析に必要な列を取得するには、これらを抽出し、スタック/分割操作を実行する必要があります (誰かがもっと簡単なアプローチを持っているかもしれません - それについて聞いていただければ幸いです
)
- したがって、行ごとのフィールド数が間違っているため、デフォルト設定は機能しません。
- 最善の方法は、行ごとに文字列全体を読み取り、recode ユーティリティと列ユーティリティを使用して残りの部分を JMP で実行することです。 これらも同様のファイルで使用できることを願っています。
- これらのことをスクリプト化するには、各ステップをテストする必要があります。ステップが問題ないと思われる場合は、スクリプトをスクリプト ウィンドウに保存またはコピーして、次のステップを実行します。
- こうして以下のスクリプトが作成されました。
Names Default to Here(1);
//Open your txt file using special settings, like } as end of line, uncheck column names, data starts row 1, ...
dt = Open(
"YOURPATH\U.txt", // exchange YOURPATH with your path to the file
columns( New Column( "c000001", Character, "Nominal" ) ),
Import Settings(
End Of Line( Semicolon, Other( "}" ) ),
End Of Field( CSV( 0 ) ),
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( 1 ),
Data Starts( 1 ),
Lines To Read( "All" ),
Year Rule( "20xx" )
)
);
// Now you have one column with in each row all information after "name"
// Remove last two lines as they are just filled with brackets
dt << Clear Selected Row States;
m = matrix({N Rows(dt)-1, N Rows(dt)});
dt << Select Rows( m);
wait(2);
dt << Delete Rows();
// Best to use Recode and Column utility functions to seperate all information
dt << New Column("recoded","Character",Formula(Recode(
:c000001,
{Substitute( _rcNow, ",{", "" ), Substitute( _rcNow, "({[{", "" ),
Substitute( _rcNow, ":", "," ), Substitute( _rcNow, "\!",\!"", ";" ),
Substitute( _rcNow, ";;", ";null;" ),
Substitute( _rcNow, "\!"", "" ), Substitute( _rcNow, ",null,", ";null;" ),
Substitute( _rcNow, ",null", ";null" )
}
)));
// Get all text seperated by ; in seperated columns
dt << Text To Columns( delimiter( ";" ), columns( :recoded ) );
dt << Delete Columns(Column(1),Column(2));
// Now you have to stack the data appropriately
colNames = dt << Get Column Names();
dt_stack = dt << Stack(
Columns(colNames),
Source Label Column( "ColName" ),
Stacked Data Column( "Data" ),
Number of Series( 2 )
);
dt_stack << Delete Columns(1,3);
// Just to Split it again to get the columns with the correct names as well the data respectively
dt_final = dt_stack << Split(
Split By( :Data ),
Split( :Data 2 ),
Sort by Column Property
);
// Close data tables you do not need anymore
close(dt_stack, NoSave);
close(dt, NoSave);
// Finally you get an alphabetic order and all data is in character. So you now need to change this appropriately.
これを経験するのは楽しかったですが、上で説明した奇妙なデータの課題を克服するのに時間がかかりました。 ただし、組み込みのスクリプトと式のおかげで、それほど多くはありません:)
もう 1 つのヒント: 再コード化された数式を取得するには、再コード化を使用してそれを数式列として保存し、数式エディターを調べれば完了です。
一番、
マーティン
必要なデータ列 (「name」、「cname」など) を含むデータ テーブルを作成します。 このデータの先頭には無関係なフェンス「({[」、最後には「]})」があります。 「{」と「}」を置き換えると、サブリストの単純なリストが作成されます。 次に、リストを反復処理し、サブリストを一度に 1 つずつ処理します。 の変数、値ペアは単純な順序になっているため、一度に 1 行をデータ テーブルに追加できます。
このアプローチを説明するための簡単なスクリプトを作成する時間がありません。