やあ、
「apple」を含むすべての列を削除し、特定の値 -9999 を持つすべての行 (列に関係なく) を削除します。 列を削除するコードを開始しましたが、取得できません。
ありがとう。
dt = Open("file.csv");
//dt = Open( "$SAMPLE_DATA/Cities.jmp" );
col_list = dt << get column names( string );
For( i = N Items( col_list ), i > 0, i--,
If(Contains( col_list[i], "apple" ),
Remove From( col_list, i ),
)
);
//dt << Select Where( );
//dt << Delete Rows;
dt << save( "testOUT.txt" );スクリプトの変更は非常に簡単です。データを入力するための特別なオプションはすべて削除できます。Open() 関数はデフォルトを使用します。
2 番目に、行の削除で実行する必要があるのは、入力列が本質的に文字であると判断された場合に、"-9999" の文字列値を検索することだけです。
名前のデフォルトは Here(1) です。
dt=開く(
"ファイル (3).csv");
// 削除する列を配置するリストを作成します
デルリスト = {};
For( i = 1, i<= N Cols(dt), i++,
If( Contains( Uppercase( as Column( i ) << get name ), "APPLE" ) > 0,
insert into(delList, column(i)< )
);
dt << 列を削除します ( delList);
// データをループし、次の行をすべて削除します
// いずれかの列の値 -9999
For( i = 1, i <= N Cols( dt ), i++,
If( Column( dt, i ) << get datatype == "Numeric",
dt << select where( As Column( dt, i ) == -9999 ),
dt << select where( Contains( As Column( dt, i ), "-9999" ) == 1 |
含む ( As 列 ( dt、i )、「99」 ) == 1
)
);
If( N Rows( dt << 選択した行を取得 ) > 0,
dt << 行を削除
);
);
ジム、
コードは機能します。
「|」を使用する場合パイプ。 余分な列が作成されます。
この場合、余分な列ヘッダーは必要ありません。合計で「12」列になります。
しかし、各列には複数のパイプ データを含めることができます。 最初の値だけを気にし、残りは無視します。
例:
"99|23|abc|x"、"99" だけを気にし、残りは無視します。
「-9999|123」、「-9999」のみを気にし、その行は後で削除されます。
1 1 1 1 1 1 2 30 40 1 10 99
1 1 1 1 1 1 2 30 40 1 10 99
1 -9999|999|231 1 1 1 1 2 30 40 1 10 99
1 1 1 1 1 1 2 30 40 1 10 99
1 1|xyz|abc 1 1 1 1 2 30 40 1 10 99
1 1 1 1 1 1 2 30 40 1 10 99
1 1 1 1 1 1 2 30 40 1 10 99
1 1 1 1 1 1 2 30 40 1 10 99
1 1 1 1 1 1 -9999 30 40 1 10 99
1 1 1 1 1 1 2 30 40 1 10 99
1 1 1 1 1 1 2 30 40 1 10 99
1 1 1 1 1 1 2 30 40 1 10 99
1 99|23|abc|x 1 1 1 1 2 30 40 1 10 99
1 1 1 1 1 1 2 30 40 1 10 99
-9999|123 1 1 1 1 1 2 30 40 1 10 99
1 1 1 1 1 1 2 30 40 1 10 99
1 1 1 1 1 1 2 30 40 1 10 99
1 1 1 1|87 1 -9999 2 30 40 1 10 99
これがあなたが望むことをするスクリプトです。スクリプトに関するいくつかのポイント:
1. Open() 関数には「|」があります。 「,」に加えて区切り文字として追加されます。これは、.csv ファイルを開くときに「データ プレビュー」を使用して簡単に作成できました。区切り文字として使用する追加の文字を選択できるようになりました。あとは、ファイルを開き、[テーブル] パネルの [ソース] エントリに移動して編集し、JMP が作成したソース コードをコピーしてファイルを開くだけです。
2. Apple を含む列の削除は一般化する必要がありました。これは、ある列では Apple と綴られ、別の列では Apple と綴られていたためです。
3. -9999 の出現を見つけたことに基づいて、行全体を削除する必要はないと思います。値 -9999 を欠損値に設定するだけでよいと思います。必要に応じて、データをそのように処理できるコードを含めました。
names default to Here(1);
dt=Open(
"file.csv",
columns(
New Column( "a", Numeric, "Continuous", Format( "Best", 12 ) ),
New Column( "b", Numeric, "Continuous", Format( "Best", 12 ) ),
New Column( "c", Numeric, "Continuous", Format( "Best", 12 ) ),
New Column( "d", Numeric, "Continuous", Format( "Best", 12 ) ),
New Column( "e", Numeric, "Continuous", Format( "Best", 12 ) ),
New Column( "g", Numeric, "Continuous", Format( "Best", 12 ) ),
New Column( "apple", Numeric, "Continuous", Format( "Best", 12 ) ),
New Column( "orange", Numeric, "Continuous", Format( "Best", 12 ) ),
New Column( "candy", Numeric, "Continuous", Format( "Best", 12 ) ),
New Column( "pizza", Numeric, "Continuous", Format( "Best", 12 ) ),
New Column( "Apple2_2", Numeric, "Continuous", Format( "Best", 12 ) ),
New Column( "orange2", Numeric, "Continuous", Format( "Best", 12 ) )
),
Import Settings(
End Of Line( CRLF, CR, LF ),
End Of Field( Comma, Other( "|" ), 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( 1 ),
Column Names Start( 1 ),
Data Starts( 2 ),
Lines To Read( "All" ),
Year Rule( "20xx" )
)
);
// Create a list to place columns to be deleted into
delList = {};
For( i = 1, i<= N Cols(dt), i++,
If( Contains( Uppercase( as Column( i ) << get name ), "APPLE" ) > 0,
insert into(delList, column(i)<<GET name=""> 0,
dt << delete rows
);
)
);
/*// Substitute the code below for the last For Loop in the above
// script, if what you want to do is to just change the -9999
// values to missing values
For( i = 1, i <= N Cols( dt ), i++,
If( Column( dt, i ) << get datatype == "Numeric",
dt << select where( As Column( dt, i ) == -9999 );
If( N Rows(dt << get selected rows) > 0,
column(dt,i)[dt << get selected rows] = .;
);
)
);*/</GET>