2017-01-10 11 views
1

私はInstagram APIを介していくつかのデータを収集しました。これはpandas DataFrameに保存されていますが、これはpandas .to_pickle()メソッドで保存されています。 `read_pickle()」メソッドを使用して、別のコンピュータ上のデータフレームをロードしようとするとなぜピクチャファイルから読み込むときにパンダがモジュールを読み込もうとしますか?

、次のエラーが返されます。

Traceback (most recent call last): 
File "examine.py", line 14, in <module> 
dataframe = pd.read_pickle(args["dataframe"]) 
File "/home/user/virtualenvs/geopandas/local/lib/python2.7/site-packages/pandas/io/pickle.py", line 65, in read_pickle 
return try_read(path) 
File "/home/user/virtualenvs/geopandas/local/lib/python2.7/site-packages/pandas/io/pickle.py", line 62, in try_read 
return pc.load(fh, encoding=encoding, compat=True) 
File "/home/user/virtualenvs/geopandas/local/lib/python2.7/site-packages/pandas/compat/pickle_compat.py", line 117, in load 
return up.load() 
File "/usr/lib/python2.7/pickle.py", line 858, in load 
dispatch[key](self) 
File "/usr/lib/python2.7/pickle.py", line 1090, in load_global 
klass = self.find_class(module, name) 
File "/usr/lib/python2.7/pickle.py", line 1124, in find_class 
__import__(module) 
ImportError: No module named instagram.models 

これを引き起こすものの任意のアイデアを?

+3

ピクルに保存されるデータには、そのタイプのオブジェクトが含まれていますか? df.head()とdf.dtypesを表示できますか? – ashishsingal

+1

'ImportError:Instagram.modelsという名前のモジュールはありません。' 'DataFrame'の中に' instagram'モデルからのオブジェクトがある可能性があります。データタイプを調べることでこれを確認することができます。 – oliversm

答えて

5

Pickleは、単にクラスを再作成する方法を知らないだけです。クラスがどのようにアンピキュレートされ、リストアされるかに関する情報は、クラス内に格納されます。__new____init____setstate__などです。

Similarly, when class instances are pickled, their class’s code and data are not pickled along with them. Only the instance data are pickled. This is done on purpose, so you can fix bugs in a class or add methods to the class and still load objects that were created with an earlier version of the class. If you plan to have long-lived objects that will see many versions of a class, it may be worthwhile to put a version number in the objects so that suitable conversions can be made by the class’s __setstate__() method.

出典:Python pickle: What can be pickled and unpickled?

だからそれをunpickle化するためには、pickleクラス(したがって、任意の中間モジュール)をロードする必要があります。

あなたが持っていない場合は/あなたは、通常のクラス(intfloatarray、...)あなたはそれをpickle化する前に、元のデータフレームに適切な値を変換する方法を確認する必要があり-module instagramをしたいです。

関連する問題