JMP 18 has a new way to integrate with Python, providing an independent Python environment designed to be used with JMP. In addition, JMP now has a native Python editor and Python packages specific to JMP. This Python environment in JMP has enhanced connectivity and interaction with JMP, which means using Python with JMP has never been easier.
Get familiar with the Python integrated development environment (IDE) in JMP 18 and learn how to
Locate the Python IDE.
Run a simple example.
Install Python packages.
Run JSL script from Python.
Send a Python variable to JSL.
Create a JMP data table from Python.
Let's start with how to find the new Python Editor.
Locating the python editor.mp4
Video Player is loading.
Current Time 0:00
/
Duration 0:31
Loaded: 0.00%
0:00
Stream Type LIVE
Remaining Time -0:31
1x
Chapters
descriptions off, selected
captions settings, opens captions settings dialog
captions off, selected
en (Main), selected
This is a modal window.
Beginning of dialog window. Escape will cancel and close the window.
End of dialog window.
This is a modal window. This modal can be closed by pressing the Escape key or activating the close button.
Now imagine that a CSV data table has been imported with pandas into Python. If we want to send it to the JSL script as a variable, we can use the Python Get function and leverage the JSL functions such as Graph Builder.
Python to JSL Variable Workflow.mp4
Video Player is loading.
Current Time 0:00
/
Duration 4:15
Loaded: 0.00%
0:00
Stream Type LIVE
Remaining Time -4:15
1x
Chapters
descriptions off, selected
captions settings, opens captions settings dialog
captions off, selected
en (Main), selected
This is a modal window.
Beginning of dialog window. Escape will cancel and close the window.
End of dialog window.
This is a modal window. This modal can be closed by pressing the Escape key or activating the close button.
Finally, let's create a new JMP data table using Python and the "jmp" module. In this example, I am using a csv file and the pandas package but this can be applied to any other type of files, especially those that cannot be opened directly in JMP.
Python to JMP Data Table Workflow.mp4
Video Player is loading.
Current Time 0:00
/
Duration 7:05
Loaded: 0.00%
0:00
Stream Type LIVE
Remaining Time -7:05
1x
Chapters
descriptions off, selected
captions settings, opens captions settings dialog
captions off, selected
en (Main), selected
This is a modal window.
Beginning of dialog window. Escape will cancel and close the window.
End of dialog window.
This is a modal window. This modal can be closed by pressing the Escape key or activating the close button.
Great info! Looking forward to trying JMP 18 -- we don't have it yet.
Just to confirm, data in python has to be pushed into data tables one column at a time? I would've expected that python could just tell JMP to open a CSV file directly.
Great info! Looking forward to trying JMP 18 -- we don't have it yet.
Just to confirm, data in python has to be pushed into data tables one column at a time? I would've expected that python could just tell JMP to open a CSV file directly.
The JMP Open, whether it is Open() in JSL or jmp.open( ) when given a CSV file will open it as a data table. The import jmp package capabilities give the ability to read, modify and create columns from the script.
import jmp
# just like you would do in JSL.
dt = jmp.open('Wafer Stacked.csv')
I want to implement this interaction between JMP and python:
Is this possible in JMP 18、Thanks Experts!:
JMP has opened a JMP file,
dt=Open("$SAMPLE_DATA/Big Class.jmp");
Then call python through JSL, python uses the data of the current table to perform python operations (it is best to call a local py file to calculate the example), python will write the results of the operation to the current table python exit.
JSL then executes further JSL code on the python result of the current file.
All the items you mentioned are very doable. In fact, you have a choice, would you rather work with a Python script or a JSL script?
Assuming you are working with a JSL script, things can be sent from JSL to Python using Python Send(). If dt is the JSL pointer to your data table, Python Send(dt) will send it to Python. This also works for JSL variables that need to be passed to Python. Python code can be executed inside a JSL script using Python Submit(). Or you might prefer Python Submit File().
Assuming you are working with a Python script, JSL commands can be executed using jmp.run_jsl(). Python can create a new JMP data table using jmp.DataTable(). Python can open an existing table using jmp.open(). Be sure to import the jmp package (import jmp).
Whichever method you choose, once Python is aware of the JMP data table, Python can direct memory read/write to JMP tables.
Let me know if you have any questions about the details.
Thank HydeMiller very much for your timely answers.
I have been using JSL with JMP software since the end of 2017 and am now completely dependent on JSL to complete my calculations. So I want to call python assistance in JSL when needed. I just want to know if there are more specific examples and code for the steps I mentioned above. Thanks again to the experts.
Directly including Python code in JSL code is tricky because of
python submit("\[here everything gets purple and no syntax highlighting is available]\")
For small Python scripts, this approach is OK. but debugging is complicated.
To jump between JSL and Python code, Workflow Builder should allow Python: Workflow Builder + Python
... and there are other options in the pipeline.
At the moment:
open a Python script window, write and debug your code - maybe play some ping-pong between a Python and a JSL script. At the end, include your python code via include and reduce the Python part in JSL to something like
Hopefully this will get you started. You will need to install numpy and pandas into your JMP/Python if you have not done so already via Python Install Packages("numpy pandas");
What log output did you get from jmputils.jpip() ?
The Python site-packages directory is not located within the JMP 18 installation directory because on most systems that's restricted to the installer and administrative users. Most companies have locked down users so that we no longer have administrative rights on our machines. If you run
import jmp
print(jmp.PY_USER_APPDIR)
It returns the top-level directory that the Python support directories are installed into.
Have you restarted JMP since running the package installs? JMP 18 has an issue that the very first time packages are installed, they may not be recognized until a restart of JMP. This is due to JMP creating the site-packages directory on demand. The issue is that when Python is initialized if it doesn't find site-packages/ it won't look for it until after a restart of JMP. Once it's established, you won't have any issues installing and immediately using packages because site-packages is now present. This has been fixed in JMP 19 development track, but not been pushed to 18 releases due to the amount of code updated.
Adding here an example where I am transforming a Python Dictionary to a JMP Data table, with ability to convert the strings to a character column and the numbers to a numeric column.