スクリプトガイド > JMPの拡張 > Pythonの操作 > Pythonインテグレーションの別例
公開日: 11/25/2021

Pythonインテグレーションの別例

Pythonにデータテーブルを送る

次の例は、Pythonに接続し、データテーブルをPythonに送り、それをログに印刷し、最後にPython接続を閉じています。

Python Init();
dt = Open( "$SAMPLE_DATA/Big Class.jmp", invisible );
Python Send( dt ); //開いているdtというデータテーブルをPythonに送る
Python Submit( "print( dt )" );
Python Term();

名前 年齢 性別 身長(インチ) 体重(ポンド)

0 KATIE 12 F 59 95

1 LOUISE 12 F 61 123

2 JANE 12 F 55 74

...

0

Pythonでのオブジェクトの作成

次の例は、Pythonに接続し、Pythonオブジェクトを作成し、そのオブジェクトをJMPで取得し、最後にPython接続を閉じています。

Python Init();
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 Term();

a -0.384649

b 0.455864

c -2.214405

d 0.260955

e 1.342286

dtype: float64

...

Pythonでの行列計算

JMPでは、単純な行列は次のような形を取ります。

xx = [1 2 3, 4 5 6, 7 8 9 ];

同じ行列が、NumPyでは配列の形を取ります。

xx = numpy.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])

もしもJMPの行列からNumPyの配列を作成するコードを生成したい場合には、次のようにプログラミングします。

q = "new = numpy.array ([";
For( i = 1, i <= N Items( xx ), i++,
	zz = Matrix( xx[i] );
	q = q || Char( zz ) || ",";
);
q = q || "])";
Show( q );
 
Python Submit( "import numpy
" || q );
Python Submit( "print(new)" );
より詳細な情報が必要な場合や、質問があるときは、JMPユーザーコミュニティで答えを見つけましょう (community.jmp.com).