簡體   English   中英

在 pandas 1.0.1 上從 1.1.5 加載 dataframe 失敗

[英]Loading dataframe from 1.1.5 fails on pandas 1.0.1

我有一個 dataframe 保存到一個泡菜(還有一堆其他的東西,作為字典)。 使用 pandas 版本 1.1.5 時保存。

我正在嘗試使用 1.0.1 版本打開它,但出現以下錯誤

File "<stdin>", line 1, in <module>
  File "/opt/conda/lib/python3.7/site-packages/pandas/core/generic.py", line 5272, in __getattr__
    if self._info_axis._can_hold_identifiers_and_holds_name(name):
  File "/opt/conda/lib/python3.7/site-packages/pandas/core/generic.py", line 5272, in __getattr__
    if self._info_axis._can_hold_identifiers_and_holds_name(name):
  File "/opt/conda/lib/python3.7/site-packages/pandas/core/generic.py", line 5272, in __getattr__
    if self._info_axis._can_hold_identifiers_and_holds_name(name):
  [Previous line repeated 493 more times]
  File "/opt/conda/lib/python3.7/site-packages/pandas/core/generic.py", line 493, in _info_axis
    return getattr(self, self._info_axis_name)
  File "/opt/conda/lib/python3.7/site-packages/pandas/core/generic.py", line 5270, in __getattr__
    return object.__getattribute__(self, name)
  File "pandas/_libs/properties.pyx", line 63, in pandas._libs.properties.AxisProperty.__get__
  File "/opt/conda/lib/python3.7/site-packages/pandas/core/generic.py", line 5270, in __getattr__
    return object.__getattribute__(self, name)
RecursionError: maximum recursion depth exceeded while calling a Python object

有沒有辦法克服這個錯誤? 我可以再次保存 dataframe,但無法在兩台計算機上降級或升級版本。

謝謝

我無法復制您的確切錯誤,但是當我嘗試使用 pandas v1.0.1 讀取由 pandas v1.1.5 創建的泡菜文件時,我得到了另一個錯誤。 我能夠通過使用羽毛格式保存文件來解決這個問題。 示例代碼:-

In [23]: cake # in version v1.1.5
Out[23]: 
     replicate recipe  temperature  angle  temp
1            1      A          175     42   175
2            1      A          185     46   185
3            1      A          195     47   195
4            1      A          205     39   205
5            1      A          215     53   215
..         ...    ...          ...    ...   ...
266         15      C          185     28   185
267         15      C          195     25   195
268         15      C          205     25   205
269         15      C          215     31   215
270         15      C          225     25   225

In [24]: cake.reset_index().to_feather("cake.feather")

在 v1.0.1 中讀取文件:

In [15]: cake = pd.read_feather("cake.feather")
In [16]: cake
Out[16]: 
     index  replicate recipe  temperature  angle  temp
0        1          1      A          175     42   175
1        2          1      A          185     46   185
2        3          1      A          195     47   195
3        4          1      A          205     39   205
4        5          1      A          215     53   215
..     ...        ...    ...          ...    ...   ...
265    266         15      C          185     28   185
266    267         15      C          195     25   195
267    268         15      C          205     25   205
268    269         15      C          215     31   215
269    270         15      C          225     25   225

In [17]: pd.__version__
Out[17]: '1.0.1'

In [18]: cake.set_index('index') # To set the index

這種方法的缺點是對pyarrow有額外的依賴,並且以羽毛二進制格式保存需要您像我上面所做的那樣重置索引

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM