2016-05-22 11 views
18

インポートパンダがエラーを投げるのではなく、などの選んだパンダのデータフレームを読み取ろうとしませんでしたという名前のモジュール:はImportError:「pandas.indexes」

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') 

トレースバックは3つの同時の例外を除いて165行です(それがどのような意味でも)。 read_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' 

私も直接、漬物から漬物ファイルをロードしようとした:

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' 
+2

を働きました古いバージョンのパンダでこれを解凍します。その後、csvなどで保存します。 pickleは、オブジェクトを再構築するためのクラス構造とモジュールポインティングに依存します。この構造が変化すると、ピクルスは壊れます。 – piRSquared

+7

古いバージョンのpandasで新しいピクルを読み込もうとしています。 pandas.indexesは0.18まで存在しません。0; pandasは後方互換性を提供していません(新しいバージョンは古いバージョンを読むことができますが、古いバージョンは新しいバージョンを読み取ることができないことを意味します) – Jeff

+2

私は0.20.2を使用しており、古いバージョンで生成されたpickleでこの問題が発生します。 – MPa

答えて

20

私は私のpython 2.7とPKLファイルを作成し、Python 3.6 でそれを読んしようとしていたときに私がやった、このエラーが発生しました:

pd.read_pickle('foo.pkl') 

をし、それは私はあなたがロードする必要があると思う

+2

私はこれが正解であるべきだと思います。これはほとんどの場合に機能しますが、 'pandas'をアップグレードすることはできません。 –

+0

これも正解でなければならないと私は同意します – Kadaj13

9

私はこの問題を、漬けたデータフレームを開こうとしています。パンダを0.18.1、パンダを0.17.1とする。 あなたがパンダをアップグレードし、PIPを使用している場合を検討し、あなたがあなたのマシン上でパンダの両方のバージョンを持っている必要がある場合は

conda upgrade pandas 

:あなたがアナコンダ、使用のようなライブラリを使用している場合

pip install --upgrade pandas 

virtualenv

+0

私のために働きました。それは細かいことですが、Python 3で正しく機能するようにpip3 install -upgrade pandasを使用しなければなりませんでした。 – Berun

2

ここでは、パンダを更新することなく、またはあなたが使用しているものは何もありません。

あなたが頻繁に動作しませんpickleを使用してpandasの異なるバージョンでのpython3

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

Python3のソリューションは私にとってはうまくいかず、最後の行で 'UnicodeDecodeError'を出します。' utf- 8 'コーデックは0番地のバイト0x80をデコードできません:無効な開始バイトです。 – user1416227

+0

はまだ私にModuleNotFoundErrorを与えます:python3.6に' pandas.indexes 'という名前のモジュールはありません – Skirrebattie

7

保存とロードを使用している場合は、python2に

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

を使用している場合。代わりにpandas.HDFStoreを使用してください。

私はパンダを更新する必要があるだけでなく、以前のバージョンではpickleで保存されたデータを必要としたときに、そのデータをHDF形式で再保存しました。もう問題はありません。

マルチインデックスのデータフレームであっても、どんな種類のパンダのデータ構造にも対応しています!要するに、バージョンアップ後に酸洗が失敗した場合は、HDFStoreを試してみてください。より信頼性があります(さらに効率的です)。

+0

このメソッドについては知りませんでした'R 'で開くことができます。 – ryanjdillon