2

我正在尝试使用 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 64bit

4

1 回答 1

-1

试试这个它为我修复了错误:

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)
        
于 2016-02-23T21:24:48.270 回答