如何使用Python将feather文件转换为CSV?

bgibtngc  于 2023-05-26  发布在  Python
关注(0)|答案(1)|浏览(200)

如何使用python将feather文件转换为csv文件?
我尝试使用feather模块,pyarrow.feather,我只能读取它,但我不能将其转换为csv格式。

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

我得到了这个错误=>

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
k4emjkb1

k4emjkb11#

即使文件很大,它仍然比feather header声称的要小。如果写入或下载文件时出现问题,则可能会发生这种情况。从评论来看,这就是本案的问题所在。所以,它不是这个代码,但无论是什么写的摆在首位。

相关问题