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 を使用している場合は、ウィザードをインタラクティブに使用することもできます (JsonWizard(1) を使用して GUI を表示します)。余分な文字を削除するにはまだ助けが必要です。上記の JSL は txt を x にロードし、substr() で 2 文字と 3 文字を削除してから、ディスクに再書き込みせずに blob を介してデータを open() に渡します。 ディスクに書き換える場合は、拡張子を .json に変更することもできます。
JMP 15's wizard also guesses the datatypes better in this exampleこの例では、JMP 15 のウィザードもデータ型をより適切に推測します。
@デビッドバーバー
いいえ、あなたは正しいです。 私は自分のアプローチに基づいて 2 時間かけてスクリプトを作成し、多くの退屈な問題に遭遇しました。 もう時間がありません。
lwx228 さん、こんにちは。
以下に、データをインポートし、適切に再コーディングし、テキストを列に配置し、スタックし、分割して最終的なテーブルを取得するスクリプトを示します。
これは非常に奇妙なデータ形式であるため、いくつかの注意事項があります。
- 区切り文字に矛盾があり、通常の txt ファイルと比較すると、次のようになります。
- コンマはフィールドで使用され、区切り記号として使用されます。
- 引用符も使用されますが、各要素には使用されません。
- 括弧はいくつかの方法で使用されます
- 欠損値に対して「null」ステートメントが存在する場合もありますが、存在しない場合もあります!
- 列名の最初の行はなく、データ フィールド内にあります。 そのため、それらを抽出し、スタック/分割操作を実行して、分析に必要な列を取得する必要があります(誰かがより簡単なアプローチを持っているかもしれません-それについて聞いていただければ幸いです;) )
- 行ごとのフィールド数が間違っているため、デフォルト設定は機能しません。
- 最善の方法は、行ごとに文字列全体を読み取り、残りを 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 つのヒント: recode 数式を取得するには、recode を使用して数式列として保存し、数式エディターを調べてください。
一番、
マーティン
必要なデータ列 ("name"、"cname" など) を含むデータ テーブルを作成します。 このデータの先頭に「({[」、末尾に「]})」という不要なフェンスがあります。 サブリストの単純なリストを作成するには、「{」と「}」を置き換えます。 次に、リストを繰り返し処理し、サブリストを 1 つずつ処理します。 の変数、値ペアは単純な順序になっているため、一度に 1 つの行をデータ テーブルに追加できます。
このアプローチを示す簡単なスクリプトを書く時間はありません。