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
在使用此函数之前,您应该阅读 user guide about ORC 和 install optional dependencies 。
此函数需要 pyarrow 库。
有关支持的 dtype,请参阅 supported ORC features in Arrow 。
目前,当 DataFrame 转换为 ORC 文件时,datetime 列中的时区不会被保留。
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()