大家好,
(JMP 17 Pro 使用者)在嘗試將資料表物件傳遞給 Python 並將它們檢索回 JSL 時,特別是在使用 Application Builder 時,遇到了一個奇怪的問題。
由於這是我第一次使用Application Builder,因此我透過標準JSL 腳本寫出了我想要在應用程式中實現的行為的粗略草案(就上下文而言,目標是一個允許使用者選擇目錄/檔案的應用程序,然後讓 JMP 產生圖表進行分析)。該行為在標準 JSL 腳本中有效,但在 Application Builder 中無效。
這是我的獨立(非應用程式產生器)腳本:
// Initialize Python within JMP
PyConnect = Python Connect();
Names Default to Here( 1 );
// Allow user to manually pick directory and file
directory = Pick Directory ("Select a directory.");
chosen_file = Pick File("Select a file", directory);
// Open the selected file, then send to Python
dt1 = Open(chosen_file, Table Contains Column Headers(0));
Python Send(dt1);
// Close the dirty data table to save space/resources
Close(dt1, NoSave);
show(dt1, "first");
// Clean the table by removing all references to "#"
Python Submit("\[
dt1 = dt1[~dt1["Column 1"].str.contains("#")]
]\");
// Retrieve the processed table from Python and open in JMP
// Terminate Python connection
dt1 = Python Get(dt1);
Python Term();
show(dt1, "second");該腳本的輸出:
dt1 = DataTable("D424TUZ0.Inspec Meas 01");
"first";
dt1 = DataTable("dt1");
"second";(不工作)這是我的應用程式生成器腳本:
executePress=Function({thisBox}, {Default Local},
// This function is called when the button is pressed
py = Python Connect();
dt1 = Open(::file, Table Contains Column Headers(0));
Close(dt1, NoSave);
show(dt1, "first");
// Clean the table by removing all references to "#"
Python Submit("\[
dt1 = dt1[~dt1["Column 1"].str.contains("#")]
]\");
dt1 = Python Get(dt1);
Python Term();
show(dt1, "second");
);以及令人不安的輸出:
dt1 = DataTable("D424TUZ0.Inspec Meas 01");
"first";
/**********/
dt1 = dt1[~dt1["Column 1"].str.contains("#")]
/**********/
dt1 = .;
"second";TLDR:在我的獨立腳本中,透過dt1 = Python Get(dt1);從 Python 中的清理中檢索資料表後,我回傳一個物件dt1 = DataTable("dt1"); 。但是,在 JMP Application Builder 腳本中,我得到dt1 = .; (對我來說這表示該物件不存在?)。
當我嘗試使用dt1 << New Data Window;時,我第一次認識到這一點。閱讀此主題讓我意識到我可能根本不使用物件: https://community.jmp.com/t5/Discussions/Error-in-running-script-Send-Expects-Scriptable-Object-in -access/td- p/718245
對於這麼長的帖子表示歉意。這是一個奇怪的錯誤,提前感謝任何人對這個問題的幫助!
我在您的應用程式產生器腳本中沒有看到任何Python Send(dt1);
另請注意,JMP 18 更改了Python Send(dt) 發生的情況。在 JMP 18 及更高版本中,您將獲得 jmp.DataTable 物件而不是 pandas.DataFrame。並且DataTable物件不再是資料的副本,而是對資料表的即時訪問,您可以直接在實時表上用Python進行處理。有關透過import jmp套件支援的 Python API 的範例,請參閱 JMP 18 中的腳本索引。
如果您需要從 jmp.DataTable 轉到 pandas.DataFrame,$SAMPLE_SCRIPTS/Python 目錄中有幾個範例。 dt2pandas.py 的作用與 JMP 14-17 的作用完全相同,將 DataTable 作為臨時 CSV 檔案儲存到磁碟,並告訴 pandas 在檔案上 read_csv() 。 JMP2pandas.py 是一個範例腳本,展示如何使用 jmp.DataTable 物件的功能並在記憶體中建立 pandas.DataFrame。
Python Get( dt ) 識別新的 jmp.DataTable 對象,而 Python Get( df ) 將識別 DataFrame 並使用 CSV 導入,與 JMP 14-17 相同
非常感謝您的詳細解決方案,這非常有幫助。我不敢相信我錯過了這麼小的事情。