ここでは、Pythonへのデータテーブル送信や、Pythonでのオブジェクト作成、行列計算の例を紹介します。
次の例では、データテーブルをPythonに送り、ファイルパスおよび列と行の数をログに出力しています。
Names Default To Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp", invisible );
Python Send( dt ); // 開いているdtというデータテーブルをPythonに送る
Python Submit( "print( dt )" );
print( dt )
Big Class (5 columns x 40 rows)
DataTable("Big Class")
次の例では、Pythonオブジェクトを作成し、そのオブジェクトをJMPで取得し、そのオブジェクトを使ってJMPデータテーブルを作成しています。
Python Submit("\[
import numpy as np
import pandas as pd
# Generate basic series
ss = pd.Series(np.random.randn(5), index=['a', 'b', 'c', 'd', 'e'])
print(ss)
sn = pd.Series(np.random.randn(5))
print(sn)
# Generate Data Frames from Series
s1 = pd.Series(np.random.randn(5), index=['a', 'b', 'c', 'd', 'e'])
print(s1)
dfs1 = pd.DataFrame(s1)
print(dfs1)
d1 = {'one' : pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
'two' : pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd'])}
print(d1)
dfd1 = pd.DataFrame(d1)
print(dfd1)
d2 = {'one' : [1., 2., 3., 4.],
'two' : [4., 3., 2., 1.]}
print(d2)
dfd2 = pd.DataFrame(d2)
print(dfd2)
]\"
);
ss = Python Get( ss );
Show( ss );
sn = Python Get( sn );
Show( sn );
dfs1 = Python Get( dfs1 );
dfs1 << New Data View;
dfd1 = Python Get( dfd1 );
dfd1 << New Data View;
dfd2 = Python Get( dfd2 );
dfd2 << New Data View;
Python Get()およびPython Send()で行列を操作するには、PythonパッケージのNumPyが必要です。NumPyがインストールされている場合、JMPは起動時にこのパッケージを自動的にインポートします。
次の例では、JSLの行列オブジェクトをPython環境に送っています。
Names Default To Here(1);
xx = [1 2 3, 3 4 5, 6 7 8];
Python Send(xx);
Python Submit("\[
import numpy
print(xx)
]\");
[[1. 2. 3.]
[3. 4. 5.]
[6. 7. 8.]]
0