あるデータ収集担当者から、データテーブルをPythonに送信し、Python内でデータを変更し、変更されたテーブルを返すことを示すサンプルがあるかどうか聞かれました。スクリプティングインデックスに見つからなかったので、共有するものを作成しました。
このスクリプトは完全な往復を示しています。データテーブルをPythonに渡し、Pythonでデータを修正し、そして結果をJSLスクリプトに返します。みんなの好きなデータテーブルを使って... ビッグクラス このスクリプトはテーブルをPythonに渡し、高さで割った重みを 'lb_inch'として作成し、変更したテーブルをJSLに返します。
JMPがデータテーブルをPythonに渡すと、PandasデータフレームがPythonオブジェクトとして作成されます。
私のマシンには複数のバージョンのPythonがインストールされているので、使用したいPythonのインストール場所をJMPに指示する必要があります。これはPythonのInit文で行われます。
Pythonの初期化(パス()、Pythonのバージョンを使用())
Path()はpython共有ライブラリへのパスです。
Use Python Version()は私が欲しいPythonのバージョンです。
Windowsでは、c:\ anaconda3 \ ... \ python36.dllの代わりにパス区切り文字をエスケープすると、c:\\ anaconda3 \\ ... \\ python36.dllになります。ファイルシステムパスの残りの部分です。
このPython Init()は私のMacにインストールされているPythonを指しています。
Names Default To Here( 1 );
Python Init(Path("/Library/Frameworks/Python.framework/Versions/3.6/lib/libpython3.6.dylib"),
Use Python Version("3.6")
);
dt1 = Open( "$SAMPLE_DATA/Big Class.jmp" );
Python Send( dt1 );
Close( dt1 );
Python Submit("print(dt1)");
Python Submit("\[
# The JMP Data table is transferred to Python as a pandas data frame
# Print out the column names
for col in dt1.columns:
print( col )
# Create a new column and apply formula to data, creating pounds per inch
# weight / height
def my_formula(w,h):
return w / h
dt1['lb_inch'] = dt1.apply(lambda row: my_formula(row['weight'],row['height']), axis=1)
dt1.head()<BR />
# print the modified table from Python
print(dt1)
]\");
<BR />// Get the modified table back from Python
dt2 = Python Get(dt1);
dt2 << New Data View;
Python Term();