데이터베이스에서 가져온 판다스 데이터 프레임이 있습니다. 한 열이 datetime64[ns] 유형입니다. 데이터 프레임을 JMP 데이터 테이블에 복사하고 싶지만, 이 게시물의 방법을 사용하면 datatime 데이터가 손실됩니다(누락된 값). https://community.jmp.com/t5/JMPer-Cable/New-in-JMP-18-Python-jmp-DataTable-and-pandas-DataFrame/ba-p/744680
예를 들면 아래와 같습니다.
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])몇 가지 해결 방법은 datetime을 문자열로 변경한 다음 새 열에서 Parse Date()를 사용하거나 datetime을 정수로 변경하고 필요한 오프셋을 추가한 다음 JMP 테이블에서 다시 포맷하는 것입니다.
// 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 );
둘 다 괜찮지만, 약간의 작업이 필요하고 중복된 열이 몇 개 남습니다. 이를 수행하는 적절한 JMP 방법이 있습니까?
저는 JMP 18.1.1을 사용하고 있습니다.
저는 두 방법 모두 괜찮다고 생각합니다. JMP는 타임스탬프를 인식하지 못하는데, 제 생각에는 당신이 알아차렸을 겁니다.)

직접 변환을 할 수도 있습니다(임시 .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);
"""
)
@jthi 감사합니다. Python Get() 메서드는 임시 .csv 파일을 저장하는 듯합니다. 지금은 해결 방법을 사용하겠지만, 판다 데이터프레임을 JMP 테이블에 복사하는 더 효율적인 내장 방식이 있으면 좋겠습니다.