Search code examples
pythonpandasdeserializationfeather

How to read into dataframe from feather bytes object


I have bytes object (it's feather data) in pandas dataframe as :

df[0]:

0 b'FEA1\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00... Name: 0, dtype: object

How to deserialization object from df[0] (feather data) into dataframe ?


Solution

  • You can do this by wrapping the bytes object in an pyarrow.BufferReader and then read the file using the actual Feather implementation in pyarrow. Note the feather package is mainly an alias nowadays for the pyarrow.feather module.

    import pyarrow as pa
    import pyarrow.feather as feather
    
    bytez = b'FEA1\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00…'
    reader = pa.BufferReader(bytez)
    df = feather.read_feather(reader)