Python Send () non riconosce il formato datetime (inviato come stringa)Quando si inviano dati a frame di dati pandas (Python), i valori numerici (datetimes) vengono inviati come stringhe.
Non mi aspetto questo comportamento, poiché ora devo affrontarlo manualmente (considerando che i datetimes in Python e JMP sono diversi).
Qualche soluzione alternativa? Immagino che il modo più semplice sarebbe trasformare il formato JMP in intero, inviare queste informazioni e trasformare la data considerando la logica dietro le date JMP (somma di secondi dalla data specifica).
ClearLog();
dt = Open( "$SAMPLE_DATA/Functional Data/Weekly Weather Data.jmp");
t = dt << Subset(
Allrows,
Columns(:DATE)
);
Python Init();
Python Send( t );
Python Submit( "
import pandas as pd
print(t.dtypes)
");
Python Term();
// Output
// DATE object
// dtype: object
// Types: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.dtypes.html
//float float64
//int int64
//datetime datetime64[ns] << Expected
//string object
//dtype: object
ScriptingOggetto: Python Send () non riconosce il formato datetime (inviato come stringa)Questa stringa di messaggio era per R, ma penso che tu possa usare lo stesso concetto per Python.
https://community.jmp.com/t5/Discussions/How-to-send-dates-as-characters-from-JMP-to-R/td-p/50112
Oggetto: Python Send () non riconosce il formato datetime (inviato come stringa)PythonSend () salva i csv temporanei che vengono letti con il valore predefinito pd.read_csv ('myfile.csv'), quindi nessun parse_date.
Per risolvere questo problema, un'opzione che non è influenzata dal formato della data:
ClearLog();
dt = Open( "$SAMPLE_DATA/Functional Data/Weekly Weather Data.jmp");
t = dt << Subset(
Allrows,
Columns(:DATE)
);
t:DATE << Format(best);
Python Init();
Python Send( t ); // send the opened data table represented by dt to Python
Python Submit( "
import pandas as pd
print(t.dtypes)
print(t.head())
t.iloc[:,0] = pd.to_datetime(t.iloc[:,0], unit='s', origin=pd.Timestamp('1904-01-01'))
print(t.dtypes)
print(t.head())
");
Python Term();
// Output
// DATE int64
// dtype: object
// DATE
// 0 3534451200
// 1 3535228800
// 2 3537648000
// 3 3538252800
// 4 3538857600
// DATE datetime64[ns]
// dtype: object
// DATE
//0 2016-01-01
//1 2016-01-10
//2 2016-02-07
//3 2016-02-14
//4 2016-02-21
Se c'è un modo migliore, fammelo sapere.