本文介绍了ImportError:没有名为"pandas.indexes"的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

导入熊猫并没有引发错误,而是尝试读取这样拾取的熊猫数据框:

Importing pandas didn't throw the error, but rather trying to read a picked pandas dataframe as such:

import numpy as np
import pandas as pd
import matplotlib
import seaborn as sns
sns.set(style="white")

control_data = pd.read_pickle('null_report.pickle')
test_data = pd.read_pickle('test_report.pickle')

回溯为165行,并发三个并发异常(无论如何). read_pickle与我正在运行的熊猫版本17.1不兼容吗?如何释放数据框以供使用?

The traceback is 165 lines with three concurrent exceptions (whatever that means). Is read_pickle not compatible with pandas version 17.1 I'm running? How do I unpickle my dataframe for use?

下面是回溯的副本:

ImportError                               Traceback (most recent call last)
C:\Users\test\Anaconda3\lib\site-packages\pandas\io\pickle.py in try_read(path, encoding)
     45             with open(path, 'rb') as fh:
---> 46                 return pkl.load(fh)
     47         except (Exception) as e:

ImportError: No module named 'pandas.indexes'

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
C:\Users\test\Anaconda3\lib\site-packages\pandas\io\pickle.py in try_read(path, encoding)
     51                 with open(path, 'rb') as fh:
---> 52                     return pc.load(fh, encoding=encoding, compat=False)
     53

C:\Users\test\Anaconda3\lib\site-packages\pandas\compat\pickle_compat.py in load(fh, encoding, compat, is_verbose)
    115
--> 116         return up.load()
    117     except:

C:\Users\test\Anaconda3\lib\pickle.py in load(self)
   1038                 assert isinstance(key, bytes_types)
-> 1039                 dispatch[key[0]](self)
   1040         except _Stop as stopinst:

C:\Users\test\Anaconda3\lib\pickle.py in load_stack_global(self)
   1342             raise UnpicklingError("STACK_GLOBAL requires str")
-> 1343         self.append(self.find_class(module, name))
   1344     dispatch[STACK_GLOBAL[0]] = load_stack_global

C:\Users\test\Anaconda3\lib\pickle.py in find_class(self, module, name)
   1383                 module = _compat_pickle.IMPORT_MAPPING[module]
-> 1384         __import__(module, level=0)
   1385         if self.proto >= 4:

ImportError: No module named 'pandas.indexes'

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
C:\Users\test\Anaconda3\lib\site-packages\pandas\io\pickle.py in read_pickle(path)
     59     try:
---> 60         return try_read(path)
     61     except:

C:\Users\test\Anaconda3\lib\site-packages\pandas\io\pickle.py in try_read(path, encoding)
     56                 with open(path, 'rb') as fh:
---> 57                     return pc.load(fh, encoding=encoding, compat=True)
     58

C:\Users\test\Anaconda3\lib\site-packages\pandas\compat\pickle_compat.py in load(fh, encoding, compat, is_verbose)
    115
--> 116         return up.load()
    117     except:

C:\Users\test\Anaconda3\lib\pickle.py in load(self)
   1038                 assert isinstance(key, bytes_types)
-> 1039                 dispatch[key[0]](self)
   1040         except _Stop as stopinst:

C:\Users\test\Anaconda3\lib\pickle.py in load_stack_global(self)
   1342             raise UnpicklingError("STACK_GLOBAL requires str")
-> 1343         self.append(self.find_class(module, name))
   1344     dispatch[STACK_GLOBAL[0]] = load_stack_global

C:\Users\test\Anaconda3\lib\pickle.py in find_class(self, module, name)
   1383                 module = _compat_pickle.IMPORT_MAPPING[module]
-> 1384         __import__(module, level=0)
   1385         if self.proto >= 4:

ImportError: No module named 'pandas.indexes'

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
C:\Users\test\Anaconda3\lib\site-packages\pandas\io\pickle.py in try_read(path, encoding)
     45             with open(path, 'rb') as fh:
---> 46                 return pkl.load(fh)
     47         except (Exception) as e:

ImportError: No module named 'pandas.indexes'

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
C:\Users\test\Anaconda3\lib\site-packages\pandas\io\pickle.py in try_read(path, encoding)
     51                 with open(path, 'rb') as fh:
---> 52                     return pc.load(fh, encoding=encoding, compat=False)
     53

C:\Users\test\Anaconda3\lib\site-packages\pandas\compat\pickle_compat.py in load(fh, encoding, compat, is_verbose)
    115
--> 116         return up.load()
    117     except:

C:\Users\test\Anaconda3\lib\pickle.py in load(self)
   1038                 assert isinstance(key, bytes_types)
-> 1039                 dispatch[key[0]](self)
   1040         except _Stop as stopinst:

C:\Users\test\Anaconda3\lib\pickle.py in load_stack_global(self)
   1342             raise UnpicklingError("STACK_GLOBAL requires str")
-> 1343         self.append(self.find_class(module, name))
   1344     dispatch[STACK_GLOBAL[0]] = load_stack_global

C:\Users\test\Anaconda3\lib\pickle.py in find_class(self, module, name)
   1383                 module = _compat_pickle.IMPORT_MAPPING[module]
-> 1384         __import__(module, level=0)
   1385         if self.proto >= 4:

ImportError: No module named 'pandas.indexes'

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
<ipython-input-17-3b05fe7d20a4> in <module>()
      3 # test_data = np.genfromtxt(fh, usecols=2)
      4
----> 5 control_data = pd.read_pickle('null_report.pickle')
      6 test_data = pd.read_pickle('test_report.pickle')
      7

C:\Users\test\Anaconda3\lib\site-packages\pandas\io\pickle.py in read_pickle(path)
     61     except:
     62         if PY3:
---> 63             return try_read(path, encoding='latin1')
     64         raise

C:\Users\test\Anaconda3\lib\site-packages\pandas\io\pickle.py in try_read(path, encoding)
     55             except:
     56                 with open(path, 'rb') as fh:
---> 57                     return pc.load(fh, encoding=encoding, compat=True)
     58
     59     try:

C:\Users\test\Anaconda3\lib\site-packages\pandas\compat\pickle_compat.py in load(fh, encoding, compat, is_verbose)
    114         up.is_verbose = is_verbose
    115
--> 116         return up.load()
    117     except:
    118         raise

C:\Users\test\Anaconda3\lib\pickle.py in load(self)
   1037                     raise EOFError
   1038                 assert isinstance(key, bytes_types)
-> 1039                 dispatch[key[0]](self)
   1040         except _Stop as stopinst:
   1041             return stopinst.value

C:\Users\test\Anaconda3\lib\pickle.py in load_stack_global(self)
   1341         if type(name) is not str or type(module) is not str:
   1342             raise UnpicklingError("STACK_GLOBAL requires str")
-> 1343         self.append(self.find_class(module, name))
   1344     dispatch[STACK_GLOBAL[0]] = load_stack_global
   1345

C:\Users\test\Anaconda3\lib\pickle.py in find_class(self, module, name)
   1382             elif module in _compat_pickle.IMPORT_MAPPING:
   1383                 module = _compat_pickle.IMPORT_MAPPING[module]
-> 1384         __import__(module, level=0)
   1385         if self.proto >= 4:
   1386             return _getattribute(sys.modules[module], name)[0]

ImportError: No module named 'pandas.indexes'

我还尝试了直接从pickle加载pickle文件:

I also tried loading the pickle file from pickle directly:

via_pickle = pickle.load( open( 'null_report.pickle', "rb" ) )

,并出现相同的错误:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-23-ba2e3adae1c4> in <module>()
      1
----> 2 via_pickle = pickle.load( open( 'null_report.pickle', "rb" ) )
      3
      4 # control_data = pd.read_pickle('null_report.pickle')
      5 # test_data = pd.read_pickle('test_report.pickle')

ImportError: No module named 'pandas.indexes'

推荐答案

当我使用python 2.7创建pkl文件并尝试使用python 3.6读取pkl文件时遇到此错误我做到了:

I had this error when I created a pkl file with python 2.7 and was trying to read it with python 3.6I did:

pd.read_pickle('foo.pkl')

它奏效了

这篇关于ImportError:没有名为"pandas.indexes"的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 20:04