942295_zh-CN
JMP 19 Python 集成:将数据表转换为 Pandas 时出现 ValueError:year 0 错误
大家好,
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">
问题:
- JMP 19 中将打开的数据表转换为 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.
- 在 JMP 19 中,应如何处理“元年”或 JMP 空日期(1904 年纪元)以避免 Python 日期时间崩溃?
</CODE>
</DIV>
</DIV>
</LINGO-BODY>
<LINGO-LABS id="lingo-labs-942295" slang="en-US" mode="CREATE">
<LINGO-LABEL>自动化和脚本编写</LINGO-LABEL>
<LINGO-LABEL>数据访问</LINGO-LABEL>
<LINGO-LABEL>数据探索与可视化</LINGO-LABEL>
<LINGO-LABEL>质量与工艺工程</LINGO-LABEL>
</LINGO-LABS>
<LINGO-SUB id="lingo-sub-942305" slang="en-US" mode="CREATE" translate="no">回复:JMP 19 Python 集成:将数据表转换为 Pandas 时出现 ValueError:year 0 错误</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">在 JMP 19 中进一步学习 Python</A>很可能是一个不错的起点。</P>
</LINGO-BODY>
<LINGO-SUB id="lingo-sub-943465" slang="en-US" mode="CREATE" translate="no">回复:JMP 19 Python 集成:将数据表转换为 Pandas 时出现 ValueError: year 0 错误</LINGO-SUB>
<LINGO-BODY id="lingo-body-943465" slang="en-US" mode="CREATE">
<P>有关<STRONG>导入 jmp</STRONG>对象 API 的最新信息,请参阅 JMP 脚本索引中的“Python”类别。文档和示例代码提供了最新更新。jmp 模块在 19 版本中进行了重大更新。</P>
<P>根据你的函数,我认为是 Pandas 抛出了 ValueError 错误:Pandas 在 JMP 18 中使用的 Python 3.11 版本和 JMP 19 中使用的 Python 3.13 版本之间发生了变化。</P>
<P>请参阅 jmp.DataTable.from_dataframe() 的脚本索引示例。其中包含多个示例,涵盖了与 JMP 数据表和其他兼容 Python 数据帧的对象(例如 Pandas、Polars、Ibis 等)之间的互操作。</P>
<P>具体来说,是“Pandas 到 JMP”和“JMP 到 Pandas”的示例。</P>
<P>JMP 转 Pandas 示例:</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)
Comments
There are no comments yet