pandas 酸洗数据帧
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23951338/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pickling a DataFrame
提问by Keith
I am trying to pickle a DataFrame with
我正在尝试使用
import pandas as pd
from pandas import DataFrame
data = pd.read_table('Purchases.tsv',index_col='coreuserid')
data.to_pickle('Purchases.pkl')
I have been running on "data" for a while and have had no issues so I know it is not a data corruption issue. I am thinking likely syntax but I have tried a number of variants. I hesitate to give the whole error message but it ends with:
我已经在“数据”上运行了一段时间并且没有出现任何问题,所以我知道这不是数据损坏问题。我在考虑可能的语法,但我尝试了许多变体。我犹豫要不要给出整个错误信息,但它以:
\pickle.pyc in to_pickle(obj, path)
13 """
14 with open(path, 'wb') as f:
15 pkl.dump(obj, f, protocol=pkl.HIGHEST_PROTOCOL)
SystemError: error return without exception set
The Purchases.pkl file is created but if I call
Purchases.pkl 文件已创建,但如果我调用
data = pd.read_pickle('Purchases.pkl')
I get EOFError. I am using Canopy 1.4 so pandas 0.13.1 which should be recent enough to have this functionality.
我收到 EOFError。我正在使用 Canopy 1.4,所以 Pandas 0.13.1 应该足够新才能拥有此功能。
采纳答案by louis_guitton
Fast forward a few years, and now it works fine. Thanks pandas ;)
快进几年,现在它工作正常。谢谢Pandas;)
回答by Darío Corral
You can try create a class from your DataFrame and pickle it after.
您可以尝试从您的 DataFrame 创建一个类,然后对其进行pickle。
This can help you: Pass pandas dataframe into class
这可以帮助您:将 Pandas 数据框传递给类

