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.
Next, let's next see a simple example in Python and how to reveal the embedded log:
Once you've determined which packages are installed, watch how to install a new one and how to upgrade pip. </CODE></P>
<P></P><iframe src="https://players.brightcove.net/6058004218001/default_default/index.html?videoId=6357446770112" width="1036" height="540" allowfullscreen allow="encrypted-media"></iframe><P></P>
<P>The code I used is below: </P>
<PRE class="bp-text bp-text-plain hljs bp-is-scrollable" tabindex="0"><CODE class="bp-text-code py"><SPAN class="hljs-selector-tag">import</SPAN> <SPAN class="hljs-selector-tag">jmp</SPAN>
<SPAN class="hljs-selector-tag">import</SPAN> <SPAN class="hljs-selector-tag">jmputils
<SPAN class="hljs-selector-id">#listing</SPAN> packages installed
jmputils<SPAN class="hljs-selector-class">.jpip</SPAN>(<SPAN class="hljs-string">'list'</SPAN>)
<SPAN class="hljs-selector-id">#Installing</SPAN> function
jmputils<SPAN class="hljs-selector-class">.jpip</SPAN>(<SPAN class="hljs-string">'install'</SPAN>,<SPAN class="hljs-string">'numpy </SPAN><SPAN class="hljs-string">pandas'</SPAN>)
<SPAN class="hljs-selector-id">#Upgrade</SPAN> pip
jmputils<SPAN class="hljs-selector-class">.jpip</SPAN>(<SPAN class="hljs-string">'install --upgrade'</SPAN>, <SPAN class="hljs-string">'pip setuptools'</SPAN>)</SPAN>
Next, let's learn about the jmp.run_jsl function that encapsulates a JSL script in Python.
The example python code I used is as follows:
<SPAN class="hljs-selector-tag"><SPAN class="hljs-keyword">import</SPAN> jmp
<BR />jmp.run_jsl(<BR /> '''<BR /> //this is a JSL comment<BR /> Open ("$Desktop/Wafer Stacked.csv")<BR /><BR /> '''<BR />)</SPAN>
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.
The code is as follows:
<SPAN class="hljs-keyword">import</SPAN> jmp
<SPAN class="hljs-keyword">import</SPAN> pandas <SPAN class="hljs-keyword">as</SPAN> pd
pd_dt= pd.read_csv(<SPAN class="hljs-string">"Wafer Stacked.csv"</SPAN>)
<SPAN class="hljs-keyword">print</SPAN> (pd_dt.head());
jmp.run_jsl(<SPAN class="hljs-string">'''
jmp_dt= Python Get (pd_dt);
jmp_dt<<
Graph Builder(
Size( 567, 444 ),
Show Control Panel( 0 ),
Show Legend( 0 ),
Variables( X( :X_Die ), Y( :Y_Die ), Color(:Defects) ),
Elements( Heatmap( X, Y, Legend( 5 ) ) )
);
'''</SPAN>)
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.
Hello,
No sure I am in the good section. I would like to create an add-in for my python script but it doesn't work. Is it possible? How?
Thanks in advance,
Ahmed
Hi @AhmedMetroEM
The better place would be raising that question as a new thread in the Discussions section of the community. That way it is also easier to find by others with similar interest: https://community.jmp.com/t5/Discussions/bd-p/discussions
You can tag me in the body with my user ID and @ before so I get a notification for your question. Then I can find it easily and answer there as others may want to chime in as well.
Short answer ahead: I'd say in general yes, it is all about the details.
#adding all columns
for i in range(len(pd_dt.columns)):
jmp_dt.new_column(pd_dt.columns[i],jmp.DataType.Character)
jmp_dt[i]=pd_dt[pd_dt.columns[i]].astype(str)
This slim version is OK for tiny data tables.
When accessing columns of large data tables, wrapping the code with Begin/End data table seems to be essential.
Python in JMP: dataframe column to datatable column best practices and computation speed implications
[for bulk data transfer in JMP19, use dt = jmp.from_dataframe(pandas_df)]