Pickling a DataFrame

冷暖自知 提交于 2019-11-29 19:18:17

问题


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

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.


回答1:


Fast forward a few years, and now it works fine. Thanks pandas ;)




回答2:


You can try create a class from your DataFrame and pickle it after.

This can help you: Pass pandas dataframe into class



来源:https://stackoverflow.com/questions/23951338/pickling-a-dataframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!