【问题标题】:Error when writing Pandas DataFrame to feather file将 Pandas DataFrame 写入羽毛文件时出错
【发布时间】:2020-06-20 00:02:26
【问题描述】:

运行时:

df.to_feather(file_path)

出现以下错误:

Traceback (most recent call last):
  File "X:\FAKE\script.py", line 37, in df_to_feather
    df.to_feather(file_path)
  File "X:\FAKE\venv\lib\site-packages\pandas\util\_decorators.py", line 214, in wrapper
    return func(*args, **kwargs)
  File "X:\FAKE\venv\lib\site-packages\pandas\core\frame.py", line 1994, in to_feather
    to_feather(self, path)
  File "X:\FAKE\venv\lib\site-packages\pandas\io\feather_format.py", line 64, in to_feather
    feather.write_feather(df, path)
  File "X:\FAKE\venv\lib\site-packages\pyarrow\feather.py", line 183, in write_feather
    writer.write(df)
  File "X:\FAKE\venv\lib\site-packages\pyarrow\feather.py", line 98, in write
    self.writer.write_array(name, col.chunk(0))
  File "pyarrow\feather.pxi", line 67, in pyarrow.lib.FeatherWriter.write_array
  File "pyarrow\error.pxi", line 105, in pyarrow.lib.check_status
pyarrow.lib.ArrowNotImplementedError: extension<pandas.period>

任何想法如何解决这个问题将不胜感激。 :)

【问题讨论】:

    标签: python pandas pyarrow feather


    【解决方案1】:

    最后一行:

    pyarrow.lib.ArrowNotImplementedError: extension<pandas.period>
    

    告诉您数据类型pandas.Period 当前未针对羽化格式实现。它是一列或您的索引。您可以尝试使用.asfreq() 方法将其转换为周期的开始/结束,也可以使用.to_timestamp() 方法将其转换为时间戳。

    【讨论】:

    • 感谢@James 这解决了我的问题。实际上,在我的 DataFrame 中有一个 Period[M] 类型的计算列。
    • 是的,接受答案有一段冷却时间。干杯:)
    猜你喜欢
    • 2019-06-18
    • 2021-06-12
    • 2018-08-22
    • 2020-11-13
    • 2020-01-12
    • 2017-01-24
    • 2013-05-31
    相关资源
    最近更新 更多