pickle 格式的数据未加载到 DataFrame 中
我得到了这段代码,其中的数据以 pickle 格式存储,我正在尝试将其解开。成功运行后,它返回以下输出: <__main__.Container at 0x232ac6bde80>
,但我希望将数据加载到 DataFrame 中以进行进一步操作。我在 StackOverflow 中搜索了可能的解决方案,但没有成功。请帮忙。这是代码:
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import rcParams
impor numpy as np
import tpickle
import skill_metrics as sm
from sys import version_info
def load_obj(name):
# Load object from file in pickle format
if version_info[0] == 2:
suffix = 'pkl'
else:
suffix = 'pkl3'
with open(name + '.' + suffix, 'rb') as f:
return pickle.load(f) # Python2 succeeds
class Container(object):
def __init__(self, pred1, pred2, pred3, ref):
self.pred1 = pred1
self.pred2 = pred2
self.pred3 = pred3
self.ref = ref
if __name__ == '__main__':
# Set the figure properties (optional)
rcParams["figure.figsize"] = [8.0, 6.4] #works
# rcParams['lines.linewidth'] = 2 # line width for plots
rcParams.update({'font.size': 12}) # font size of axes text
# Close any previously open graphics windows
plt.close("all")
# Read data from pickle file
load_obj('target_data')
df = pd.read_pickle('target_data.pkl')
df
谢谢。
I got this code that has data stored in pickle format, I am trying to unpickle it. After it successfully ran, it was returning this output: <__main__.Container at 0x232ac6bde80>
, but I want the data loaded into the DataFrame for further manipulations. I have searched StackOverflow for possible solutions to no avail. Kindly help. Here is the code:
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import rcParams
impor numpy as np
import tpickle
import skill_metrics as sm
from sys import version_info
def load_obj(name):
# Load object from file in pickle format
if version_info[0] == 2:
suffix = 'pkl'
else:
suffix = 'pkl3'
with open(name + '.' + suffix, 'rb') as f:
return pickle.load(f) # Python2 succeeds
class Container(object):
def __init__(self, pred1, pred2, pred3, ref):
self.pred1 = pred1
self.pred2 = pred2
self.pred3 = pred3
self.ref = ref
if __name__ == '__main__':
# Set the figure properties (optional)
rcParams["figure.figsize"] = [8.0, 6.4] #works
# rcParams['lines.linewidth'] = 2 # line width for plots
rcParams.update({'font.size': 12}) # font size of axes text
# Close any previously open graphics windows
plt.close("all")
# Read data from pickle file
load_obj('target_data')
df = pd.read_pickle('target_data.pkl')
df
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论