JMP18: Python: jmp.Datatable: HowTo get column names without converting to pandas dataframeTrying to create a new column in a jmp.Datatable and check if it already exists.
Need to get list of column names
Automation and ScriptingRe: JMP18: Python: jmp.Datatable: HowTo get column names without converting to pandas dataframeFrom which it is a simple check to see if the name is in the list.
if 'age' in col_names:
print('found age')Re: JMP18: Python: jmp.Datatable: HowTo get column names without converting to pandas dataframeThe data table is an iterable collection of columns.
import jmp
dt = jmp.open(jmp.SAMPLE_DATA + 'Big Class.jmp')
col_names = [ x.name for x in dt]
print(col_names)
Resulting in
['name', 'age', 'sex', 'height', 'weight']
Re: HowTo get column names of jmp.Datatable without converting to pandas dataframeYou can always fall back to jsl using jmp.run_jsl
CNames = jmp.run_jsl('''
Data Table( "Powered by Python" ) << Get Column Names( Continuous, String );
''')
Or you could maybe loop over the columns check them with col_obj.name
import jmp
dt = jmp.open(jmp.SAMPLE_DATA + "Big Class.jmp")
print(dt[0].name)
Comparing column names might not be that easy in JMP and you might want to use something like << Has Column with jmp.run_jsl (data table : message column exists(colname)? - JMP User Community)

Re: HowTo get column names of jmp.Datatable without converting to pandas dataframeThanks for the inputs.
My bad for not mentioning that was trying to do it in the python environment
Sample code below
import jmp
import jmputils
dt = jmp.current() # get current datatable
dt.new_column('colA', jmp.DataType.Character)Want to check if colA exists before creating a new one
Re: HowTo get column names of jmp.Datatable without converting to pandas dataframeHere is the method I normally use to determine if a specific column is or is not in the data table
Names Default To Here( 1 );
dt =
// Open Data Table: Big Class.jmp
// → Data Table( "Big Class" )
Open( "$SAMPLE_DATA/Big Class.jmp" );
If( Try( :mycolumn << get name, "" ) == "",
New Column( "mycolumn" )
);
Re: HowTo get column names of jmp.Datatable without converting to pandas dataframeHi
One sample from JSL index
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
n = dt << Get Column Names();
Show( n );
CNames = dt << Get Column Names( Continuous );
Show( CNames );
SNames = dt << Get Column Names( String );
Show( SNames );
