Hello Everyone,
I am upgrading my scripts from JMP18 to JMP19 and 'm hitting a particular roadblock with this integration. In JMP 18, I used custom function to loop through columns and create Pandas DataFrame. It worked perfectly. However in JMP19, the exact code throws a ValueError: year 0 is out of range.
Here is the snippet:
Python Send("raw_data");
</CODE></DIV>
<DIV class="Y3BBE" data-sfc-cp="" data-sfc-root="c" data-sfc-cb="" data-hveid="CAEIBRAA" data-complete="true" data-processed="true">
<PRE>def jmp_to_pandas(jmp_table):
cols = list(jmp_table)
data_dict = {}
for col in cols:
data_dict[col.name] = list(col)
return pd.DataFrame(data_dict)
</PRE>
<CODE class="KDcb0c" dir="ltr" data-sae="" data-complete="true" data-sfc-cb="" data-sfc-root="c">data1 = jmp_to_pandas(raw_data)
</CODE></DIV>
<DIV class="Y3BBE" data-sfc-cp="" data-sfc-root="c" data-sfc-cb="" data-hveid="CAEIBRAA" data-complete="true" data-processed="true"><CODE class="KDcb0c" dir="ltr" data-sae="" data-complete="true" data-sfc-cb="" data-sfc-root="c">
Questions:
- What is the official JMP 19 way to convert an open Data Table to a Pandas DataFrame?
- Has the
jmp module structure changed? I'm finding it difficult to locate the updated JMP 19 Python API reference on the website.
- How should "Year 0" or JMP null dates (1904 epoch) be handled in JMP 19 to avoid Python datetime crashes?
</CODE></DIV>
</DIV></LINGO-BODY><LINGO-LABS id="lingo-labs-942295" slang="en-US" mode="CREATE"><LINGO-LABEL>Automation and Scripting</LINGO-LABEL><LINGO-LABEL>Data Access</LINGO-LABEL><LINGO-LABEL>Data Exploration and Visualization</LINGO-LABEL><LINGO-LABEL>Quality and Process Engineering</LINGO-LABEL></LINGO-LABS><LINGO-SUB id="lingo-sub-942305" slang="en-US" mode="CREATE" translate="no">Re: JMP 19 Python Integration: ValueError: year 0 when converting Data Table to Pandas</LINGO-SUB><LINGO-BODY id="lingo-body-942305" slang="en-US" mode="CREATE"><P><A href="https://community.jmp.com/t5/JMPer-Cable/Going-further-with-Python-in-JMP-19/m-p/898522#U898522" class="lia-mention-container-editor-message lia-img-icon-blog-thread lia-fa-icon lia-fa-blog lia-fa-thread lia-fa" target="_blank">Going further with Python in JMP 19</A> is most likely a good starting point</P></LINGO-BODY><LINGO-SUB id="lingo-sub-943465" slang="en-US" mode="CREATE" translate="no">Re: JMP 19 Python Integration: ValueError: year 0 when converting Data Table to Pandas</LINGO-SUB><LINGO-BODY id="lingo-body-943465" slang="en-US" mode="CREATE"><P>For the latest information on the <STRONG>import jmp</STRONG> object's API see the Scripting Index 'Python' category in JMP. Documentation and sample code provide the latest updates. There are significant updates to the jmp module in 19. </P>
<P>Given your function, I would say it's Pandas that is throwing the ValueError:. Pandas has changed between its Python 3.11 version used in 18 and the Python 3.13 version utilized in JMP 19. </P>
<P>See the Scripting index example on jmp.DataTable.from_dataframe(). There are multiple examples there, both to and from JMP data tables and other dataframe compatible Python objects: Pandas; Polars; Ibis; ...</P>
<P>Specifically, 'Pandas to JMP' and 'JMP to Pandas' examples.</P>
<P>JMP to Pandas sample:</P>
<PRE class="lia-code-sample language-python"><CODE>import jmp
import jmputils
try:
if not jmputils.is_installed('pandas'):
jmputils.jpip('install', 'pandas', echo=False)
except Exception as e:
print(f'Install failed with exception: {e}')
import pandas as pd
dt = jmp.open(jmp.SAMPLE_DATA + "Big Class.jmp")
pandas_df = (pd.api.interchange.from_dataframe(dt))
print(pandas_df)