cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
lala
Level VIII

Does python write data from memory to JMP only in a circular form?

import jmp;file_path = r"C:\0\test.txt"
data = []
with open(file_path, 'r') as file:
    for line in file:
        row = line.strip().split('\t')
        data.append([float(row[0]), float(row[1])])
dt = jmp.DataTable("New Table", len(data)) 
col_A = dt.new_column('A', jmp.DataType.Numeric)
col_B = dt.new_column('B', jmp.DataType.Numeric)
for i, (a, b) in enumerate(data):
    dt['A'][i] = a
    dt['B'][i] = b

 

 

 

Does this form work as in the original JSL code?

dt[0,0] = data[0,0]

Thanks Experts!

 

8 REPLIES 8
lala
Level VIII

Re: Does python write data from memory to JMP only in a circular form?

I try it,not word.

import jmp;file_path = r"C:\0\test.txt"
data = []
with open(file_path, 'r') as file:
    for line in file:
        row = line.strip().split('\t')
        data.append([float(row[0]), float(row[1])])
r=len(data)
print(f"num {b}")
jmp.run_jsl("""
ar=Python Get(date[]);r=Python Get(b);
d2=New Table("test",Add Rows(r),New Column("A"),New Column("B"));
d2[0,0] = ar[0,0]

""")
jthi
Super User

Re: Does python write data from memory to JMP only in a circular form?

Scripters Club Recording: Running Python Code within JSL, there are examples in your JMP installation folder \18\Samples\Scripts\Python and I think some in scripting guide Additional JSL-to-Python Examples (jmp.com). More can be found from many presentations by Paul (I also mention these in my presentation from Scripters Club)

-Jarmo
lala
Level VIII

Re: Does python write data from memory to JMP only in a circular form?

This loop form of the code I posted is already implemented.

I'm just wondering if python has this feature

dt[0,0] = data[0,0]

 

Experts said that I have seen these content, but my English skills are poor, and programming knowledge is not much.Still not solved.

If I had found a way, I wouldn't have spent so much time writing this post.

 

So ask the experts if they can help.

jthi
Super User

Re: Does python write data from memory to JMP only in a circular form?

Which feature? Data table subscripting and setting all values of data table from matrix?

You can set all values with run_jsl

import jmp

file_path = r"C:\Users\jarmo\Downloads\test(1).txt"
data = []

with open(file_path, 'r') as file:
    for line in file:
        row = line.strip().split('\t')
        data.append([float(row[0]), float(row[1])])

jmp.run_jsl("""
m = Python Get(data);

dt = New Table("test", 
	Add Rows(N Items(m)),
	New Column("A"),
	New Column("B")
);
	
dt[0,0] = m
""")
-Jarmo
lala
Level VIII

Re: Does python write data from memory to JMP only in a circular form?

Thanks Experts!

 

dt[0,0] = m
d2[0,0] = ar[0,0]

2024-09-13_06-52-20.png

lala
Level VIII

Re: Does python write data from memory to JMP only in a circular form?

In addition, ask an expert: how to concatenate two JMP tables with the same column names in a python environment?

Do also want to call JSL's concatenation code?

 

Thanks!

jthi
Super User

Re: Does python write data from memory to JMP only in a circular form?

Quickly checking from scripting index it looks like that would be the easiest option. 

-Jarmo

Re: Does python write data from memory to JMP only in a circular form?

Examples of this functionality is in the Scripting Index.  It's also basic Python, these objects were designed to behave with the functionality a Python programmer would expect.  The data table object's mapping operator [ ] gives you back a column object reference, which can then be iterated across for the row value.  The data table mapping can take either the 'name' or the 0 based index. So where i, and j are both integers

dt[ i ][ j ] is still perfectly valid.  

 

As is the following

for x in dt:
  x[row] = value

Here this iterates across dt in order without needing to know either the index or the name of the column.

 

The key to remember is that the dt object is a collection of columns, and the column is a collection of rows, so the indexing is dt[ column ] [ row ].

Also len(dt) returns number of columns as does dt.ncols.

Similarly len( dt[0] ) returns the length of the first column as does dt.nrows since all columns are the same length.