【发布时间】:2022-08-24 19:01:36
【问题描述】:
我正在尝试使用 Pyarrow 将 Pandas DataFrame 保存为 .orc 文件。包的版本是:pandas==1.3.5 和pyarrow==6.0.1。我的 python3 版本是3.9.12。
这是代码sn-p:
import pandas as pd
import pyarrow as pa
import pyarrow.orc as orc
df = pd.read_orc(\'sample.orc\')
table = pa.Table.from_pandas(df, preserve_index=False)
orc.write_table(table, \'sample_rewritten.orc\')
我得到的错误是:ArrowNotImplementedError: Unknown or unsupported Arrow type: null
如何在 python 中将 Pandas DataFrame (csv) 保存为 .orc 文件?
write_table 行失败。
这是整个堆栈跟踪:
ArrowNotImplementedError Traceback (most recent call last)
Input In [1], in <cell line: 7>()
5 df = pd.read_orc(\'hats_v2_sample.orc\')
6 table = pa.Table.from_pandas(df, preserve_index=False)
----> 7 orc.write_table(table, \'sample_rewritten.orc\')
File /opt/homebrew/lib/python3.9/site-packages/pyarrow/orc.py:176, in write_table(table, where)
174 table, where = where, table
175 writer = ORCWriter(where)
--> 176 writer.write(table)
177 writer.close()
File /opt/homebrew/lib/python3.9/site-packages/pyarrow/orc.py:146, in ORCWriter.write(self, table)
136 def write(self, table):
137 \"\"\"
138 Write the table into an ORC file. The schema of the table must
139 be equal to the schema used when opening the ORC file.
(...)
144 The table to be written into the ORC file
145 \"\"\"
--> 146 self.writer.write(table)
File /opt/homebrew/lib/python3.9/site-packages/pyarrow/_orc.pyx:159, in pyarrow._orc.ORCWriter.write()
File /opt/homebrew/lib/python3.9/site-packages/pyarrow/error.pxi:120, in pyarrow.lib.check_status()
ArrowNotImplementedError: Unknown or unsupported Arrow type: null
-
哪条线到底失败了?
from_pandas还是write_table?你能提供完整的堆栈跟踪吗? -
我已经用整个堆栈跟踪更新了这个问题
-
看起来您的源表有一个
pa.null()类型的列(这意味着它没有任何数据)。看起来兽人也不支持空列。您需要找出导致问题的列以及原因。为此,您可以致电print(table.schema),它会告诉您每列的类型。 -
好的,谢谢。
标签: python-3.x pandas pyarrow orc