Python Pandas and JMPHi all
I discussed Python and JMP with JMP Partners. During the discussion, they asked two questions.
1. How to covert Python pandas columns to JMP Column (directly) without saving it ?
2. In case of doing Python Init( ) in JMP, there is some problem that Pandas doesn't be imported
1) When we run Python Init() in JMP, we import like below.
import pandas as _JMPpd
(Python3.6 is coonected with JMP and Pandas is already installed in Python3.6)|
Picture 1 is the result of pandas import and version check
2) But, there is some error in JMP, Picture 2
Other module(ex, sqlalchemy, pymssql etc) is OK, there is error only in Pandas.
Re: Python Pandas and JMPWe discussed this problem again but it seems there is some error.
Python API doesn't seem to be stable. There is some error in pyplot library of matplotlib.

But OK in Python.

How about the following process ?
1. Starting JMP Process with JMP Python API
from win32com.client import Dispatch
jmp = Dispatch("JMP.Application")
jmp.visible=True #False
2. Working Python Pandas (starting data processing with Python)
3. The result of Pandas convert to JMP file
Fot this, JMP need to offer JMP Sned library in Python like Python Get()
4. Starting JMP Script
Starting Script after dt=Current Data Table()
Re: Python Pandas and JMPThanks Paul,
With your comment, I would have deep discussion time with our partner
Thanks again
Re: Python Pandas and JMPWell the previous anwser just showed getting a python object back, not getting the data from pandas as had intended. Here is a better example. That borrows code from StackOverflow on getting data from dataframe to numpy.
https://stackoverflow.com/questions/13187778/convert-pandas-dataframe-to-numpy-array-preserving-index?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
JMP has a bug, that it doesn't appear to be able to import a numpy array unless it's all the same data type... So this example puts the data into the data frame, then gets it back out into another dictionary, which does transfer back to JMP.
Python Init();
Python Submit("\[
import pandas as pd
import numpy as np
print('Pandas Version: ' + pd.__version__)
data = {'state':['Ohio','Ohio','Ohio','Nevada','Nevada','Nevada'],'year':[2000,2001,2002,2001,2002,2003], 'pop':[1.5,1.7,3.6,2.4,2.9,3.2]
}
df = pd.DataFrame(data)
print(df)
v = df.values
print(v)
cols = df.columns
types = [(cols[i], df[k].dtype.type) for (i, k) in enumerate(cols)]
dtype = np.dtype(types)
array = np.zeros(v.shape[0], dtype)
for (i, k) in enumerate(array.dtype.names):
array[k] = v[:, i]
print(array.dtype.names);
print(array)
d={}
l=[]
for (i, k) in enumerate(array.dtype.names):
d[k] = v[:,i].tolist()
print(d)
print('leaving python')
]\");
Print("inJSL");
pyData = Python Get(d);
Print(data);
Python Term();
Giving the following output
Pandas Version: 0.22.0
pop state year
0 1.5 Ohio 2000
1 1.7 Ohio 2001
2 3.6 Ohio 2002
3 2.4 Nevada 2001
4 2.9 Nevada 2002
5 3.2 Nevada 2003
[[1.5 'Ohio' 2000]
[1.7 'Ohio' 2001]
[3.6 'Ohio' 2002]
[2.4 'Nevada' 2001]
[2.9 'Nevada' 2002]
[3.2 'Nevada' 2003]]
('pop', 'state', 'year')
[(1.5, 'Ohio', 2000) (1.7, 'Ohio', 2001) (3.6, 'Ohio', 2002)
(2.4, 'Nevada', 2001) (2.9, 'Nevada', 2002) (3.2, 'Nevada', 2003)]
{'pop': [1.5, 1.7, 3.6, 2.4, 2.9, 3.2], 'state': ['Ohio', 'Ohio', 'Ohio', 'Nevada', 'Nevada', 'Nevada'], 'year': [2000, 2001, 2002, 2001, 2002, 2003]}
leaving python
"inJSL"
["pop" => {1.5, 1.7, 3.6, 2.4, 2.9, 3.2}, "state" => {"Ohio", "Ohio", "Ohio", "Nevada", "Nevada", "Nevada"}, "year" => {2000, 2001, 2002, 2001, 2002, 2003}]
0Re: Python Pandas and JMPJMP's python support is a work in progress, please bear with us as we continute to improve its capabilities and ease of use. I have run the code below in JMP 14.1 on the Mac using Python 3.6.4 directly from Python.org
Pandas is being imported, it's just that variables on a line are not being evaluated to the log window. If you wrap it with a print(pd.__version__) you do get the value to the log. The code below shows that, and shows taking a pandas DataFrame and getting the data back into JMP as a script object.
Python Init(Path("/Library/Frameworks/Python.framework/Versions/3.6/lib/libpython3.6.dylib"), Use Python Version("3.6") );
Python Submit("\[
import pandas as pd
print('Pandas Version: ' + pd.__version__)
data = {'state':['Ohio','Ohio','Ohio','Nevada','Nevada','Nevada'],'year':[2000,2001,2002,2001,2002,2003], 'pop':[1.5,1.7,3.6,2.4,2.9,3.2]
}
frame = pd.DataFrame(data)
print(frame)
]\");
data = Python Get(data);
Print(data);
Python Term();
The results from this code:
Pandas Version: 0.22.0
pop state year
0 1.5 Ohio 2000
1 1.7 Ohio 2001
2 3.6 Ohio 2002
3 2.4 Nevada 2001
4 2.9 Nevada 2002
5 3.2 Nevada 2003
["pop" => {1.5, 1.7, 3.6, 2.4, 2.9, 3.2}, "state" => {"Ohio", "Ohio", "Ohio", "Nevada", "Nevada", "Nevada"}, "year" => {2000, 2001, 2002, 2001, 2002, 2003}]
0
From the script object it can be processed into a new data table