我尝试使用cPickle加载一个文件,如下所示:
import cPickle
cPickle.load(open('test', 'rb'))
然而,我得到了这个错误,
---------------------------------------------------------------------------
UnpicklingError Traceback (most recent call last)
<ipython-input-527-1b7653ff1917> in <module>()
----> 1 cPickle.load(open('test', 'rb'))
UnpicklingError: unpickling stack underflow
有时它会给出这样的错误
UnpicklingError: could not find MARK
有什么理由让我得到这个吗?
PS: cPickle不会与我一起处理任何文件,即使是新创建的只包含两个单词的文件。我使用的是ubuntu 12.04和Python 64位
发布于 2016-02-24 05:24:48
试试这个,它为我修复了这个错误:
import pickle
import pandas as pd
# read in csv file to pandas dataframe and save as pickle file
training_data = pd.read_csv('train.csv')
pickle_out = open('train.pkl', 'wb')
pickle.dump(training_data, pickle_out)
pickle_out.close()
# open pickle file
file = 'train.pkl'
with open(file, 'rb') as f:
training_data = pickle.load(f)
https://stackoverflow.com/questions/15691657
复制相似问题