官网说明

  • apache arrow官网说明
  • pandas官网说明
  • feather github项目

    简介

    feather是hadoop架构中一种形式简单的表格数据格式,可以作为各种编程语言之间通用的表格文件格式。其设计理念简洁明了,即一个文件就是一张表,非计算机专业人士也可以很快掌握基础用法。这种数据格式在制造业的生产线日志数据中非常适合使用。

    基础使用

    安装,注意不是feather而是feather-format
    1. pip install feather-format
    读写类似于pandas.read_csv(),支持文件名或流
    推荐不要使用pandas.read_feather()pandas.write_feather(),使用feather库原生的函数可以设置更多选项,这有点像h5py的dict式写法和create_dataset()的关系。
    import pyarrow.feather as feather
    # 写
    feather.write_feather(df, '/path/to/file')
    with open('/path/to/file', 'wb') as f:
      feather.write_feather(df, f)
    # 读
    read_df = feather.read_feather('/path/to/file')
    with open('/path/to/file', 'rb') as f:
      read_df = feather.read_feather(f)
    
    设置更多选项:
    读:指定列、内存映射、多线程等。官网说明
    读取feather文档不能像SQLite那样通过where方法来指定要读取的行,只能指定列名。
    写:压缩、分块。官网说明
    写入feather文档时不能通过只更改有变化的数据来减少开销,只能把所有数据全部重新写入

    注意事项

    feather可以存储所有常见数值类型、utf-8字符串和datetime,但是不能存储python object
    feather要求pandas数据保持默认的index,在存储前要进行reset_index()reset_index(drop=true)。可参考reset_index说明