DRAFT help

Scripting Guide > Python > JSL-to-Python Interfaces > Additional JSL-to-Python Examples
Publication date: 07/08/2024

Additional JSL-to-Python Examples

The following examples show how to send a data table to Python, create objects in Python, and use matrix operations in Python.

Send a Data Table to Python

This example sends a data table to Python and prints the file path and number of columns and rows to the log.

Names Default To Here(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp", invisible );
Python Send( dt ); // Send the opened data table represented by dt to Python
Python Submit( "print( dt )" );
 
print( dt )

Big Class (5 columns x 40 rows)

DataTable("Big Class")

Create Objects in Python

This example creates a Python object, retrieves the object into JMP, and uses the object to create a JMP data table.

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;

Matrix Operations in Python

Use of Python Get() and Python Send() with a Matrix requires the presence of the Python package NumPy. JMP automatically attempts to import this at runtime, requiring only the import of the package.

The following example sends a JSL matrix object to the Python environment.

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

Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).