How can I convert a feather file to CSV using Python?

807 Views Asked by At

How to convert feather file into csv file using python?

I tried using feather module, pyarrow.feather I could only read it but I couldn't convert it to csv format.

# when using pandas
import pandas as pd
df = pd.read_feather('coffee_ratings_full.feather')

I got this error=>

ArrowInvalid                              Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_26876/2731998856.py in <module>
----> 1 df = pd.read_feather('coffee_ratings_full.feather')

~\Anaconda3\lib\site-packages\pandas\io\feather_format.py in read_feather(path, columns, use_threads, storage_options)
    128     ) as handles:
    129 
--> 130         return feather.read_feather(
    131             handles.handle, columns=columns, use_threads=bool(use_threads)
    132         )

~\Anaconda3\lib\site-packages\pyarrow\feather.py in read_feather(source, columns, use_threads, memory_map, **kwargs)
    224         The contents of the Feather file as a pandas.DataFrame
    225     """
--> 226     return (read_table(
    227         source, columns=columns, memory_map=memory_map,
    228         use_threads=use_threads).to_pandas(use_threads=use_threads, **kwargs))

~\Anaconda3\lib\site-packages\pyarrow\feather.py in read_table(source, columns, memory_map, use_threads)
    250         The contents of the Feather file as a pyarrow.Table
    251     """
--> 252     reader = _feather.FeatherReader(
    253         source, use_memory_map=memory_map, use_threads=use_threads)
    254 

~\Anaconda3\lib\site-packages\pyarrow\_feather.pyx in pyarrow._feather.FeatherReader.__cinit__()

~\Anaconda3\lib\site-packages\pyarrow\error.pxi in pyarrow.lib.pyarrow_internal_check_status()

~\Anaconda3\lib\site-packages\pyarrow\error.pxi in pyarrow.lib.check_status()

ArrowInvalid: File is too small to be a well-formed file
1

There are 1 best solutions below

0
tdelaney On

Even though the file is large, its still smaller than the feather headers claim it should be. That can happen if there was a problem writing or downloading the file. From the comments, that was the problem in this case. So, its not this code, but whatever wrote it in the first place.