First the syntax for << Execute ( ) is wrong. See the example in the scripting index. The first parameter for Execute is a JSL list of inputs, followed by a JSL list of output variables, followed by the script, and then optional echo(1 or 0) parameter.
The script should be delineate by JSL's 'raw' string markers "\[ script here ]\" to ensure white space and line endings are preserved. I am surprised you are not getting a syntax error, but I see the same lack of error on 19... I'm looking into that. The show preds_df for me simply printed
dt = .;
which is missing. This then of course means:
dt << New Data View
Throws an error because dt ( missing ) is not scriptable.
The below code replicates your issue.
conn = Python Connect();
conn << Get Version();
conn << Execute( "
import pandas as pd
import numpy as np
pandas_df = pd.DataFrame(
{
"A": 1.0,
"B": pd.Timestamp("20130102"),
"C": pd.Series(1, index=list(range(4)), dtype="float32"),
"D": np.array([3] * 4, dtype="int32"),
"E": pd.Categorical(["test", "train", "test", "train"]),
"F": "foo",
}
)
print(pandas_df)
]\", echo(1) );
dt = Python Get(pandas_df);
show(dt);
dt << New Data View;
This code runs as expected
conn = Python Connect();
conn << Get Version();
conn << Execute( {},{},"\[
import pandas as pd
import numpy as np
pandas_df = pd.DataFrame(
{
"A": 1.0,
"B": pd.Timestamp("20130102"),
"C": pd.Series(1, index=list(range(4)), dtype="float32"),
"D": np.array([3] * 4, dtype="int32"),
"E": pd.Categorical(["test", "train", "test", "train"]),
"F": "foo",
}
)
print(pandas_df)
]\", echo(1) );
dt = Python Get(pandas_df);
show(dt);
dt << New Data View;
A couple things of note JMP 17 is the last version that utilized Python from the user's environment, rather than an embedded Python installed with JMP 18 and newer. In JMP 14-17 the Python Send (dt); created a pandas dataframe in the Python environment by saving the Data Table to a temporary CSV file, then causing pandas to read that CSV file into a dataframe. Python Get( df ); behaved analogously buy having pandas write the dataframe to a CSV file and have JMP import the CSV file. This meant that you had 2 copies of the data the JMP data table, and the pandas dataframe.
This changed in JMP 18 with the introduction of the embedded Python 3.11.x and a builtin jmp import package that provides a jmp.DataTable class. This introduces an in-memory live reference to the JMP data table accessible from Python. Python Send( dt ); in JMP 18+ now creates a jmp.DataTable object instead of a pandas datagram. dt2 = Python Get( dt ) just gets the data table reference assigning to the variable. dfdt = Python Get( data_frame ); still uses the old mechanism to convert and load the dataframe as a data table via CSV file. In JMP 18 there is a Python sample script in the scripts directory shown how to do the original dt->csv->df and df->csv->dt conversions. JMP 19 supports the Portable Dataframe Protocol so it's a one-liner to go dt->df or df->dt in memory. Samples named dt2pandas.jsl, dt2pands.py, dt2pandas2dt.py
For JMP 17:
Names Default to here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
// I have multiple Python's on system so I choose 3.10 where I have
// matplotlib, pandas, numpy, ... installed
Python Init(Use Python Version("3.10"));
Python Send(dt);
close(dt);
dtdf = Python Get("dt");
Show(dtdf);
dtdf << New Data View;
This works fine on my machine. If you can't get this to run please examine your Log to see if you are showing errors. Modifying Python Init() either for your environment if necessary.
JMP 19
conn = Python Connect();
conn << Get Version();
conn << Execute( {},{},"\[
import jmp
import pandas as pd
import numpy as np
pandas_df = pd.DataFrame(
{
"A": 1.0,
"B": pd.Timestamp("20130102"),
"C": pd.Series(1, index=list(range(4)), dtype="float32"),
"D": np.array([3] * 4, dtype="int32"),
"E": pd.Categorical(["test", "train", "test", "train"]),
"F": "foo",
}
)
print( pandas_df )
# JMP 19 create a data table direcly from a dataframe
dt = jmp.from_dataframe(pandas_df)
print( dt )
]\", echo(1) );
show(dt);
// dt << New Data View; // already on screen
Much more can be done with just running the Python script from the editor no JSL wrapper needed in JMP 18+