cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. EST on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-819635%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EImportazione%20della%20colonna%20datetime%20dal%20dataframe%20pandas%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-819635%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHo%20un%20data%20frame%20pandas%20che%20%C3%A8%20stato%20importato%20da%20un%20database.%20Una%20colonna%20%C3%A8%20nel%20tipo%20datetime64%5Bns%5D.%20Voglio%20copiare%20il%20dataframe%20in%20una%20tabella%20dati%20JMP%2C%20tuttavia%20i%20dati%20datatime%20vengono%20persi%20(valori%20mancanti)%20quando%20si%20utilizza%20il%20metodo%20in%20questo%20post%3A%20%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2FJMPer-Cable%2FNew-in-JMP-18-Python-jmp-DataTable-and-pandas-DataFrame%2Fba-p%2F744680%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Fcommunity.jmp.com%2Ft5%2FJMPer-Cable%2FNew-in-JMP-18-Python-jmp-DataTable-and-pandas-DataFrame%2Fba-p%2F744680%3C%2FA%3E%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3EDi%20seguito%20un%20esempio%3A%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CPRE%3Eimport%20jmp%0Aimport%20pandas%20as%20pd%0Afrom%20pandas.api.types%20import%20is_object_dtype%2C%20is_numeric_dtype%2C%20is_bool_dtype%2C%20is_string_dtype%2C%20is_datetime64_dtype%0A%0Adf%20%3D%20pd.DataFrame(%7B'txt'%3A%20%5B'A'%2C%20'B'%5D%2C%0A%09'num'%3A%20%5B%20123%2C%20543%20%5D%2C%20%0A%09'time'%3A%20%5Bpd.to_datetime('2024-11-24%2012%3A34%3A56')%2C%20pd.to_datetime('2024-11-25%2012%3A34%3A56')%5D%7D)%0A%0A%23%20-------%20WORKAROUNDS%20BELOW%20-------%0A%23%20Creating%20two%20new%20columns%20to%20get%20the%20datetime%20column%20to%20JMP%20data%20table%0A%23%20%20Convert%20datetime%20to%20epoch%20and%20add%20Num(%2001Jan1970%20)%20to%20match%20JMP's%20method%3A%0Adf%5B'datetime_epoch'%5D%20%3D%20df%5B'time'%5D.astype('int64')%2F%2F1e9%20%2B%202082844800%20%0A%23%20%20or...%20create%20new%20column%20with%20datetime%20as%20a%20string%0Adf%5B'time_str'%5D%20%3D%20df%5B%20'time'%20%5D.astype('str')%0A%23%20-------%0A%0Adt0%20%3D%20jmp.DataTable(%20'tb'%2C%20df.shape%5B0%5D%20)%0A%23%20get%20the%20column%20names%20from%20the%20data%20frame%0Anames%20%3D%20list(df.columns)%0Afor%20j%20in%20range(%20df.shape%5B1%5D%20)%3A%0A%09%23%20check%20if%20the%20coulumn%20data%20type%20is%20string%20or%20numeric%0A%09if%20is_string_dtype(df%5B%20names%5Bj%5D%20%5D%20)%3A%0A%09%09dt0.new_column(names%5Bj%5D%2C%20jmp.DataType.Character%20)%0A%09else%3A%0A%09%09dt0.new_column(names%5Bj%5D%2C%20jmp.DataType.Numeric%20)%0A%09%23%20populate%20the%20JMP%20column%20with%20data%0A%09dt0%5Bj%5D%20%3D%20list(df.iloc%5B%3A%2Cj%5D)%3C%2FPRE%3E%3CP%3EUn%20paio%20di%20soluzioni%20alternative%20consistono%20nel%20modificare%20la%20data%20e%20l'ora%20in%20una%20stringa%20e%20quindi%20utilizzare%20Parse%20Date()%20in%20una%20nuova%20colonna%2C%20oppure%20convertire%20la%20data%20e%20l'ora%20in%20un%20numero%20intero%2C%20aggiungere%20l'offset%20necessario%20e%20quindi%20riformattarlo%20nella%20tabella%20JMP.%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%2F%2F%20New%20column%20to%20parse%20the%20string%20format%20date%0AData%20Table(%20%22tb%22%20)%3AColumn%206%20%26lt%3B%26lt%3B%20Input%20Format(%20%22d%2Fm%2Fy%20h%3Am%3As%22%2C%200%20)%20%26lt%3B%26lt%3B%0AFormat(%20%22d%2Fm%2Fy%20h%3Am%3As%22%2C%2022%2C%200%20)%20%26lt%3B%26lt%3B%20Set%20Formula(%20Parse%20Date(%20%3Atime_str%20)%20)%3B%0A%0A%2F%2F%20Convert%20the%20epoch%20date%20format%20to%20human%20readable%0AData%20Table(%20%22tb%22%20)%3Adatetime_epoch%20%26lt%3B%26lt%3B%20Input%20Format(%20%22d%2Fm%2Fy%20h%3Am%3As%22%2C%200%20)%20%26lt%3B%26lt%3B%0AFormat(%20%22d%2Fm%2Fy%20h%3Am%3As%22%2C%2022%2C%200%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EEntrambe%20sono%20OK%2C%20ma%20richiedono%20un%20po'%20di%20lavoro%20e%20lasciano%20alcune%20colonne%20ridondanti.%20Esiste%20un%20modo%20corretto%20di%20JMP%20per%20farlo%3F%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3ESto%20utilizzando%20JMP%2018.1.1.%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-819635%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3EAutomazione%20e%20scripting%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAccesso%20ai%20dati%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-819661%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Importazione%20della%20colonna%20datetime%20dal%20dataframe%20pandas%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-819661%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EPenso%20che%20entrambi%20i%20metodi%20siano%20corretti.%20JMP%20non%20riconosce%20la%20marca%20temporale%2C%20cosa%20che%20credo%20tu%20abbia%20notato)%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22jthi_1-1732816645626.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_1-1732816645626.png%22%20style%3D%22width%3A%20346px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_1-1732816645626.png%22%20style%3D%22width%3A%20346px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F70718iC86434B4FC696FA4%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22jthi_1-1732816645626.png%22%20alt%3D%22jthi_1-1732816645626.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EPuoi%20anche%20effettuare%20una%20conversione%20diretta%20(penso%20che%20questo%20potrebbe%20utilizzare%20un%20file%20.csv%20temporaneo)%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Eimport%20jmp%0Aimport%20pandas%20as%20pd%0Afrom%20pandas.api.types%20import%20is_object_dtype%2C%20is_numeric_dtype%2C%20is_bool_dtype%2C%20is_string_dtype%2C%20is_datetime64_dtype%0A%0Adf%20%3D%20pd.DataFrame(%7B'txt'%3A%20%5B'A'%2C%20'B'%5D%2C%0A%09'num'%3A%20%5B%20123%2C%20543%20%5D%2C%20%0A%09'time'%3A%20%5Bpd.to_datetime('2024-11-24%2012%3A34%3A56')%2C%20pd.to_datetime('2024-11-25%2012%3A34%3A56')%5D%7D)%0A%0Ajmp.run_jsl(%22%22%22%0A%09dt%20%3D%20Python%20Get(df)%3B%0A%09dt%20%26lt%3B%26lt%3B%20new%20data%20view%3B%0A%09Python%20Send(dt)%3B%0A%22%22%22%0A)%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CCODE%20class%3D%22%20language-jsl%22%3E%3C%2FCODE%3E%3C%2FP%3E%0A%3CP%3E%20%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-819752%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20Importazione%20della%20colonna%20datetime%20dal%20dataframe%20pandas%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-819752%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EGrazie%20%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F14366%22%20target%3D%22_blank%22%3E%40jthi%3C%2FA%3E%20.%20Il%20metodo%20Python%20Get()%20sembra%20salvare%20un%20file%20.csv%20temporaneo.%20Per%20ora%20user%C3%B2%20le%20soluzioni%20alternative%2C%20ma%20sarebbe%20bello%20avere%20un%20modo%20integrato%20pi%C3%B9%20efficiente%20per%20copiare%20i%20dataframe%20pandas%20nelle%20tabelle%20JMP.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
matth1
Level IV

Importing datetime column from pandas dataframe

I have a pandas data frame which has been imported from a database. One column is in the datetime64[ns] type. I want to copy the dataframe into a JMP data table, however the datatime data is lost (missing values) when using the method in this post: https://community.jmp.com/t5/JMPer-Cable/New-in-JMP-18-Python-jmp-DataTable-and-pandas-DataFrame/ba-...

 

An example is below:

 

import jmp
import pandas as pd
from pandas.api.types import is_object_dtype, is_numeric_dtype, is_bool_dtype, is_string_dtype, is_datetime64_dtype

df = pd.DataFrame({'txt': ['A', 'B'],
	'num': [ 123, 543 ], 
	'time': [pd.to_datetime('2024-11-24 12:34:56'), pd.to_datetime('2024-11-25 12:34:56')]})

# ------- WORKAROUNDS BELOW -------
# Creating two new columns to get the datetime column to JMP data table
#  Convert datetime to epoch and add Num( 01Jan1970 ) to match JMP's method:
df['datetime_epoch'] = df['time'].astype('int64')//1e9 + 2082844800 
#  or... create new column with datetime as a string
df['time_str'] = df[ 'time' ].astype('str')
# -------

dt0 = jmp.DataTable( 'tb', df.shape[0] )
# get the column names from the data frame
names = list(df.columns)
for j in range( df.shape[1] ):
	# check if the coulumn data type is string or numeric
	if is_string_dtype(df[ names[j] ] ):
		dt0.new_column(names[j], jmp.DataType.Character )
	else:
		dt0.new_column(names[j], jmp.DataType.Numeric )
	# populate the JMP column with data
	dt0[j] = list(df.iloc[:,j])

A couple of workarounds are to either change the datetime to a string then use Parse Date() in a new column, or concert the datetime to an integer, add the necessary offset and then reformat it in the JMP table.

 

 

 

// New column to parse the string format date
Data Table( "tb" ):Column 6 << Input Format( "d/m/y h:m:s", 0 ) <<
Format( "d/m/y h:m:s", 22, 0 ) << Set Formula( Parse Date( :time_str ) );

// Convert the epoch date format to human readable
Data Table( "tb" ):datetime_epoch << Input Format( "d/m/y h:m:s", 0 ) <<
Format( "d/m/y h:m:s", 22, 0 );

Both are OK, but require some work and leave some redundant columns. Is there a proper JMP way of doing this?

 

I'm using JMP 18.1.1.

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Importing datetime column from pandas dataframe

I think both of those methods are ok.JMP doesn't recognize the timestamp which I think you did notice)

jthi_1-1732816645626.png

You can also do direct conversion (I think this might use temporary .csv)

import jmp
import pandas as pd
from pandas.api.types import is_object_dtype, is_numeric_dtype, is_bool_dtype, is_string_dtype, is_datetime64_dtype

df = pd.DataFrame({'txt': ['A', 'B'],
	'num': [ 123, 543 ], 
	'time': [pd.to_datetime('2024-11-24 12:34:56'), pd.to_datetime('2024-11-25 12:34:56')]})

jmp.run_jsl("""
	dt = Python Get(df);
	dt << new data view;
	Python Send(dt);
"""
)

 

-Jarmo

View solution in original post

2 REPLIES 2
jthi
Super User

Re: Importing datetime column from pandas dataframe

I think both of those methods are ok.JMP doesn't recognize the timestamp which I think you did notice)

jthi_1-1732816645626.png

You can also do direct conversion (I think this might use temporary .csv)

import jmp
import pandas as pd
from pandas.api.types import is_object_dtype, is_numeric_dtype, is_bool_dtype, is_string_dtype, is_datetime64_dtype

df = pd.DataFrame({'txt': ['A', 'B'],
	'num': [ 123, 543 ], 
	'time': [pd.to_datetime('2024-11-24 12:34:56'), pd.to_datetime('2024-11-25 12:34:56')]})

jmp.run_jsl("""
	dt = Python Get(df);
	dt << new data view;
	Python Send(dt);
"""
)

 

-Jarmo
matth1
Level IV

Re: Importing datetime column from pandas dataframe

Thanks @jthi. The Python Get() method does seem to save a temporary .csv file. I'll use the workarounds for now, but it would be nice to have a more efficient built-in way of copying pandas dataframes to JMP tables.

Recommended Articles