首页 > 解决方案 > 尝试加载泡菜文件时出现错误

问题描述

我有一个 .pickle 文件,我试图打开它进行分析,但直到现在我还没有成功。

我用过这个代码:`import pickle import pandas as pd

with open("ToyData.pickle", 'rb') as pickle_file:
    data=pickle.load(pickle_file)`

但我收到了这个错误

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-13-16f33a5337fb> in <module>
      2 import pandas as pd
      3 with open("ToyData.pickle", 'rb') as pickle_file:
----> 4     data=pickle.load(pickle_file)

AttributeError: Can't get attribute 'PandasIndexAdapter' on <module 'xarray.core.indexing' from 'C:\\Users\\unknow\\anaconda3\\lib\\site-packages\\xarray\\core\\indexing.py'>

我什至尝试安装 xarray 但仍然收到此错误。我什至使用谷歌colab。我也尝试过熊猫

import pandas as pd

object = pd.read_pickle(r'C:\Users\unknow\Desktop\Formation Tech4Tchad\Programmation Python\ToyData.pickle')

但我收到此错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-bd99c94998ad> in <module>
      1 import pandas as pd
      2 
----> 3 object = pd.read_pickle(r'C:\Users\unknow\Desktop\Formation Tech4Tchad\Programmation Python\ToyData.pickle')

~\anaconda3\lib\site-packages\pandas\io\pickle.py in read_pickle(filepath_or_buffer, compression, storage_options)
    220                 #  "No module named 'pandas.core.sparse.series'"
    221                 #  "Can't get attribute '__nat_unpickle' on <module 'pandas._libs.tslib"
--> 222                 return pc.load(handles.handle, encoding=None)
    223         except UnicodeDecodeError:
    224             # e.g. can occur for files written in py27; see GH#28645 and GH#31988

~\anaconda3\lib\site-packages\pandas\compat\pickle_compat.py in load(fh, encoding, is_verbose)
    272         up.is_verbose = is_verbose
    273 
--> 274         return up.load()
    275     except (ValueError, TypeError):
    276         raise

~\anaconda3\lib\pickle.py in load(self)
   1210                     raise EOFError
   1211                 assert isinstance(key, bytes_types)
-> 1212                 dispatch[key[0]](self)
   1213         except _Stop as stopinst:
   1214             return stopinst.value

~\anaconda3\lib\pickle.py in load_stack_global(self)
   1535         if type(name) is not str or type(module) is not str:
   1536             raise UnpicklingError("STACK_GLOBAL requires str")
-> 1537         self.append(self.find_class(module, name))
   1538     dispatch[STACK_GLOBAL[0]] = load_stack_global
   1539 

~\anaconda3\lib\site-packages\pandas\compat\pickle_compat.py in find_class(self, module, name)
    204         key = (module, name)
    205         module, name = _class_locations_map.get(key, key)
--> 206         return super().find_class(module, name)
    207 
    208 

~\anaconda3\lib\pickle.py in find_class(self, module, name)
   1579         __import__(module, level=0)
   1580         if self.proto >= 4:
-> 1581             return _getattribute(sys.modules[module], name)[0]
   1582         else:
   1583             return getattr(sys.modules[module], name)

~\anaconda3\lib\pickle.py in _getattribute(obj, name)
    329             obj = getattr(obj, subpath)
    330         except AttributeError:
--> 331             raise AttributeError("Can't get attribute {!r} on {!r}"
    332                                  .format(name, obj)) from None
    333     return obj, parent

AttributeError: Can't get attribute 'PandasIndexAdapter' on <module 'xarray.core.indexing' from 'C:\\Users\\unknow\\anaconda3\\lib\\site-packages\\xarray\\core\\indexing.py'>

我已经卸载并安装了熊猫,但这并不能解决我的问题。任何建议都会有所帮助。谢谢

标签: pythonpandaspickle

解决方案


推荐阅读