JMP 18新增了與 Python 整合的方式,提供了一個專為與 JMP 搭配使用而設計的獨立 Python 環境。此外,JMP 現在擁有原生 Python 編輯器和 JMP 專用的 Python 軟體套件。 JMP 中的 Python 環境增強了與 JMP 的連接性和互動性,這意味著將 Python 與 JMP 結合使用變得前所未有的便捷。
熟悉 JMP 18 中的 Python 整合開發環境 (IDE),並學習如何
- 找到 Python IDE。
- 運行一個簡單的例子。
- 安裝 Python 套件。
- 從 Python 運行 JSL 腳本。
- 將 Python 變數傳送到 JSL。
- 從 Python 建立 JMP 資料表。
讓我們從如何找到新的 Python 編輯器開始。
接下來,我們來看看一個 Python 中的簡單範例以及如何顯示嵌入的日誌:
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>我使用的程式碼如下:</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>
接下來我們來了解Python中封裝了JSL腳本的jmp.run_jsl函數。
我使用的範例python程式碼如下:
<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>
現在假設我們已經用 Pandas 將一個 CSV 資料表匯入 Python。如果我們想將其作為變數傳送到 JSL 腳本,我們可以使用Python 的 Get函數,並利用 Graph Builder 等 JSL 函數。
程式碼如下:
<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>)
最後,讓我們使用 Python 和「jmp」模組來建立一個新的 JMP 資料表。在本例中,我使用了 csv 檔案和 pandas 包,但這也適用於任何其他類型的文件,尤其是那些無法在 JMP 中直接開啟的文件。
你好,
我不確定我是否在好的部分。我想為我的 Python 腳本創建一個插件,但是它不起作用。是否可以?如何?
先謝,
艾哈邁德
嗨@AhmedMetroEM
更好的辦法是將該問題作為社區討論部分的一個新主題提出。這樣,有類似興趣的人也更容易找到它: https://community.jmp.com/t5/Discussions/bd-p/discussions
您可以在正文中使用我的使用者 ID 和 @ 標記我,這樣我就會收到有關您的問題的通知。然後我可以輕鬆找到它並在那裡回答,因為其他人可能也想加入。
簡短回答:我的回答總的來說是的,但一切都取決於細節。
#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)
這種精簡版適用於小型數據表。
存取大型資料表的列時,用「開始/結束資料表」包裹代碼似乎是必不可少的。
JMP 中的 Python:資料框列到資料表列的最佳實務及對計算速度的影響
[在 JMP19 中進行批次資料傳輸時,請使用 dt = jmp.from_dataframe(pandas_df)]