pandas.DataFrame.to_orc#
- DataFrame.to_orc(path=None, *, engine='pyarrow', index=None, engine_kwargs=None)[源代码]#
将 DataFrame 写入 Optimized Row Columnar (ORC) 格式。
- 参数:
- pathstr, 类文件对象 或 None, 默认 None
如果为字符串,则在写入分区数据集时将用作根目录路径。类文件对象是指具有 write() 方法的对象,例如文件句柄(例如,通过内置的 open 函数)。如果 path 为 None,则返回一个 bytes 对象。
- engine{‘pyarrow’}, 默认 ‘pyarrow’
要使用的 ORC 库。
- indexbool, 可选
如果为
True,则将 DataFrame 的索引包含在文件输出中。如果为False,则它们不会写入文件。如果为None,类似于infer,DataFrame 的索引将被保存。但是,RangeIndex 不会作为值保存,而是存储在元数据中作为范围,因此不需要太多空间且速度更快。其他索引将作为列包含在文件输出中。- engine_kwargsdict[str, Any] 或 None, 默认 None
传递给
pyarrow.orc.write_table()的其他关键字参数。
- 返回:
- 如果未提供
path参数,则返回 bytes,否则返回 None 如果未指定
path,则返回包含 DataFrame 数据的 Bytes 对象,否则返回 None。
- 如果未提供
- 引发:
- NotImplementedError
一个或多个列的数据类型为 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。
注意
在此处查找有关 ORC 的更多信息 here。
此函数需要 pyarrow 库。
有关支持的数据类型,请参阅 Arrow 中支持的 ORC 功能。
当前,将数据帧转换为 ORC 文件时,日期时间列中的时区不会被保留。
示例
>>> 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()