gpt4 book ai didi

python - cPickle 下溢错误

转载 作者:行者123 更新时间:2023-11-28 19:25:01 26 4
gpt4 key购买 nike

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

最佳答案

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

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)

关于python - cPickle 下溢错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15691657/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com