pandas.DataFrame.to_orc#

DataFrame.to_orc(path=None, *, engine='pyarrow', index=None, engine_kwargs=None)[源代码]#

将 DataFrame 写入 ORC 格式。

在 1.5.0 版本加入.

Parameters:
pathstr、文件类对象或 None,默认为 None

如果为字符串,则在写入分区数据集时用作根目录路径。文件类对象是指具有 write() 方法的对象,例如文件句柄(例如,通过内置的 open 函数)。如果 path 为 None,则会返回一个 bytes 对象。

engine{‘pyarrow’},默认为 ‘pyarrow’

要使用的 ORC 库。

indexbool, optional

如果为 True,则将 DataFrames的索引包含在文件输出中。如果为 False,它们将不会写入文件。如果为 None,则类似于 infer,将保存 DataFrames 的索引。但是,RangeIndex 将存储为元数据中的范围,而不是作为值存储,因此不需要太多空间并且速度更快。其他索引将作为列包含在文件输出中。

engine_kwargsdict[str, Any] 或 None,默认为 None

传递给 pyarrow.orc.write_table() 的附加关键字参数。

Returns:
如果未提供 path 参数,则为 bytes,否则为 None
Raises:
NotImplementedError

一个或多个列的 Dtype 为 category、unsigned integers、interval、period 或 sparse。

ValueError

engine 不是 pyarrow。

参见

read_orc

读取 ORC 文件。

DataFrame.to_parquet

写入 parquet 文件。

DataFrame.to_csv

写入 csv 文件。

DataFrame.to_sql

写入 sql 表。

DataFrame.to_hdf

写入 hdf。

Notes

Examples

>>> df = pd.DataFrame(data={'col1': [1, 2], 'col2': [4, 3]})
>>> df.to_orc('df.orc')  
>>> pd.read_orc('df.orc')  
   col1  col2
0     1     4
1     2     3

如果您想获取或c内容的缓冲区,可以将其写入 io.BytesIO

>>> import io
>>> b = io.BytesIO(df.to_orc())  
>>> b.seek(0)  
0
>>> content = b.read()