<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python Send() does not recognize datetime format (sent as string) in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Python-Send-does-not-recognize-datetime-format-sent-as-string/m-p/309043#M56314</link>
    <description>&lt;P&gt;PythonSend() saves temporary csv which are read with the default pd.read_csv('myfile.csv'), hence no parse_date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To deal with this, one option which is not impacted by the date format:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;ClearLog();

dt = Open( "$SAMPLE_DATA/Functional Data/Weekly Weather Data.jmp");

t = dt &amp;lt;&amp;lt; Subset(
			Allrows,
			Columns(:DATE)
			);


t:DATE &amp;lt;&amp;lt; 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&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If there is a better way, let me know.&lt;/P&gt;</description>
    <pubDate>Fri, 18 Sep 2020 14:34:34 GMT</pubDate>
    <dc:creator>FN</dc:creator>
    <dc:date>2020-09-18T14:34:34Z</dc:date>
    <item>
      <title>Python Send() does not recognize datetime format (sent as string)</title>
      <link>https://community.jmp.com/t5/Discussions/Python-Send-does-not-recognize-datetime-format-sent-as-string/m-p/306352#M56186</link>
      <description>&lt;P&gt;When sending datatables to pandas dataframes (Python), numeric values (datetimes) are sent as strings.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would not expect this behavior, since now I have to deal with this manually (considering datetimes in Python and JMP are different).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any workaround? I imagine the easiest would be to transform the JMP format to integer, send this information, and transform the date considering the logic behind JMP dates (sum of seconds since specific date).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;ClearLog();

dt = Open( "$SAMPLE_DATA/Functional Data/Weekly Weather Data.jmp");

t = dt &amp;lt;&amp;lt; 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]  &amp;lt;&amp;lt; Expected
//string              object
//dtype: object&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 23:37:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Python-Send-does-not-recognize-datetime-format-sent-as-string/m-p/306352#M56186</guid>
      <dc:creator>FN</dc:creator>
      <dc:date>2023-06-09T23:37:53Z</dc:date>
    </item>
    <item>
      <title>Re: Python Send() does not recognize datetime format (sent as string)</title>
      <link>https://community.jmp.com/t5/Discussions/Python-Send-does-not-recognize-datetime-format-sent-as-string/m-p/308999#M56311</link>
      <description>&lt;P&gt;This message string was for R, but I think you can use the same concept for Python.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.jmp.com/t5/Discussions/How-to-send-dates-as-characters-from-JMP-to-R/td-p/50112" target="_blank"&gt;https://community.jmp.com/t5/Discussions/How-to-send-dates-as-characters-from-JMP-to-R/td-p/50112&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2020 13:25:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Python-Send-does-not-recognize-datetime-format-sent-as-string/m-p/308999#M56311</guid>
      <dc:creator>ih</dc:creator>
      <dc:date>2020-09-18T13:25:26Z</dc:date>
    </item>
    <item>
      <title>Re: Python Send() does not recognize datetime format (sent as string)</title>
      <link>https://community.jmp.com/t5/Discussions/Python-Send-does-not-recognize-datetime-format-sent-as-string/m-p/309043#M56314</link>
      <description>&lt;P&gt;PythonSend() saves temporary csv which are read with the default pd.read_csv('myfile.csv'), hence no parse_date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To deal with this, one option which is not impacted by the date format:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;ClearLog();

dt = Open( "$SAMPLE_DATA/Functional Data/Weekly Weather Data.jmp");

t = dt &amp;lt;&amp;lt; Subset(
			Allrows,
			Columns(:DATE)
			);


t:DATE &amp;lt;&amp;lt; 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&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If there is a better way, let me know.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2020 14:34:34 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Python-Send-does-not-recognize-datetime-format-sent-as-string/m-p/309043#M56314</guid>
      <dc:creator>FN</dc:creator>
      <dc:date>2020-09-18T14:34:34Z</dc:date>
    </item>
  </channel>
</rss>

