Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/52.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ImportError:没有名为';熊猫指数';_Python_Numpy_Pandas_Pickle - Fatal编程技术网

Python ImportError:没有名为';熊猫指数';

Python ImportError:没有名为';熊猫指数';,python,numpy,pandas,pickle,Python,Numpy,Pandas,Pickle,导入pandas不会引发错误,而是尝试读取拾取的pandas数据帧: 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行,有三

导入pandas不会引发错误,而是尝试读取拾取的pandas数据帧:

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\u pickle
是否与我正在运行的pandas 17.1版不兼容?如何取消数据帧的链接以供使用

以下是回溯的副本:

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'

我遇到了这个问题,因为我试图用pandas 0.17.1打开一个用pandas 0.18.1制作的腌制数据框。 如果您使用的是pip,请使用以下工具升级pandas:

pip install --upgrade pandas
如果您正在使用像anaconda这样的库,请使用:

conda upgrade pandas

如果你需要在你的机器上有两个版本的熊猫,考虑使用< /P> < P>,我试图用熊猫0.171打开一个用熊猫0.18.1的腌制的数据框来解决这个问题。 如果您使用的是pip,请使用以下工具升级pandas:

pip install --upgrade pandas
如果您正在使用像anaconda这样的库,请使用:

conda upgrade pandas

如果你需要在你的机器上有两个版本的熊猫,请考虑使用

< P>这是一个解决方案,不需要更新熊猫或你使用的任何东西。 如果你用的是蟒蛇2

import cPickle
with open('filename.pkl', 'rb') as fo:
        dict = cPickle.load(fo, encoding='latin1’)
如果你用的是蟒蛇3

import pickle
with open('filename.pkl', 'rb') as fo:
        dict = pickle.load(fo, encoding='latin1’)

这是一个解决方案,不需要更新pandas或您使用的任何东西

如果你用的是蟒蛇2

import cPickle
with open('filename.pkl', 'rb') as fo:
        dict = cPickle.load(fo, encoding='latin1’)
如果你用的是蟒蛇3

import pickle
with open('filename.pkl', 'rb') as fo:
        dict = pickle.load(fo, encoding='latin1’)

使用
pickle
在不同版本的
pandas
中保存和加载通常不起作用。相反,使用

当我需要更新pandas,但也需要在以前的版本中使用pickle保存一些数据时,我返回并以HDF格式重新保存这些数据,而其他格式都不起作用。没有问题了


适用于任何类型的数据结构,甚至是多索引数据帧!简而言之,如果版本升级后酸洗失败,请尝试HDFStore;它更可靠(也更高效!)。

在不同版本的
pandas
中保存和加载使用
pickle
通常不起作用。相反,使用

当我需要更新pandas,但也需要在以前的版本中使用pickle保存一些数据时,我返回并以HDF格式重新保存这些数据,而其他格式都不起作用。没有问题了


适用于任何类型的数据结构,甚至是多索引数据帧!简而言之,如果版本升级后酸洗失败,请尝试HDFStore;它更可靠(也更高效!)。

当我用python 2.7创建pkl文件并试图用python 3.6读取它时,出现了这个错误 我做到了:


当我用Python2.7创建一个pkl文件并试图用Python3.6读取它时,出现了这个错误 我做到了:


在熊猫0.23.4中,有更好的方法解决这个问题。使用
pandas.read_pickle
读取文件对象,如:


pd.read\u pickle(open('test\u report.pickle','rb'))

在pandas 0.23.4中,有一种更好的方法来解决问题。使用
pandas.read_pickle
读取文件对象,如:


pd.read\u pickle(打开('test\u report.pickle','rb'))
如果您想读取pickle文本而不是文件,请执行以下操作

import io

pd.read_pickle(io.BytesIO(pickled_text))
如果遇到错误-
值错误:无法识别的压缩类型:推断,
明确提到压缩类型。它可以是None(无压缩)、gzip、bz2、xz或zip(取决于文件扩展名)中的一个。

pd.read\u pickle(io.BytesIO(pickled\u text),compression=None)
如果您想读取pickle text而不是文件,请执行以下操作

import io

pd.read_pickle(io.BytesIO(pickled_text))
如果遇到错误-
值错误:无法识别的压缩类型:推断,
明确提到压缩类型。它可以是None(无压缩)、gzip、bz2、xz或zip(取决于文件扩展名)中的一个。

pd.read\u pickle(io.BytesIO(pickled\u text),compression=None)
处理中断取消勾选的内部API更改的灵活方法是实现自定义取消勾选器实例

例如,
pandas.index
模块已移动到
pandas.core.index
。我们可以编写一个取消勾选器,它相应地调整模块路径。为此,我们可以覆盖方法
find\u class

import sys
class Unpickler(pickle.Unpickler):
    def find_class(self, module, name):
        '''This method gets called for every module pickle tries to load.'''
        # python 2 --> 3 compatibility: __builtin__ has been renamed to builtins
        if module == '__builtin__':
            module = 'builtins'
        # pandas compatibility: in newer versions, pandas.indexes has been moved to pandas.core.indexes
        if 'pandas.indexes' in module:
            module = module.replace('pandas.indexes', 'pandas.core.indexes')
        __import__(module)
        return getattr(sys.modules[module], name)

with open('/path/to/pickle.pkl', 'rb') as file:
    pdf = Unpickler(file).load()

处理中断取消勾选的内部API更改的灵活方法是实现自定义取消勾选实例

例如,
pandas.index
模块已移动到
pandas.core.index
。我们可以编写一个取消勾选器,它相应地调整模块路径。为此,我们可以覆盖方法
find\u class

import sys
class Unpickler(pickle.Unpickler):
    def find_class(self, module, name):
        '''This method gets called for every module pickle tries to load.'''
        # python 2 --> 3 compatibility: __builtin__ has been renamed to builtins
        if module == '__builtin__':
            module = 'builtins'
        # pandas compatibility: in newer versions, pandas.indexes has been moved to pandas.core.indexes
        if 'pandas.indexes' in module:
            module = module.replace('pandas.indexes', 'pandas.core.indexes')
        __import__(module)
        return getattr(sys.modules[module], name)

with open('/path/to/pickle.pkl', 'rb') as file:
    pdf = Unpickler(file).load()

我想你需要加载一个旧版本的熊猫来解开这个。然后另存为csv或其他内容。Pickle依赖于类结构和模块指向来重构对象。如果此结构发生更改,pickle将中断。您正在尝试使用较旧版本的pandas读取较新的pickle。指数在0.18.0之前不存在;pandas提供back compat而不是forward compat(意味着较新版本可以读取较旧版本,但较旧版本不能读取较新版本)我使用的是0.20.2,并且使用较旧版本生成的pickle存在此问题。我使用的是0.20.3,并且在较旧的pickle文件中也会出现此错误。@r3罗伯逊尝试使用
pd.read\u pickle
,如前所述,我认为您需要加载较旧版本的pandas来解除此链接。然后另存为csv或其他内容。Pickle依赖于类结构和模块指向来重构对象。如果此结构发生更改,pickle将中断。您正在尝试使用较旧版本的pandas读取较新的pickle。指数在0.18.0之前不存在;pandas提供back compat而不是forward compat(意味着较新版本可以读取较旧版本,但较旧版本不能读取较新版本)我使用的是0.20.2,并且使用较旧版本生成的pickle存在此问题。我使用的是0.20.3,并且在较旧的pickle文件中也会出现此错误。@r3罗伯逊尝试使用
pd.read\u pickle
,如前所述,您的python3解决方案不适合我,它提供了一个
UnicodedeCoder