Skip to content
Advertisement

Pickle data not loading

Here I the data I try to save as a “pickle file”

import pandas as pd
import pickle as pkl

df_1 = pd.DataFrame({'TIME': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 'speed': [2, 3, 7, 6, 13, 24, 31, 64, 100, 202], 
                    'altitude': [10, 2, 1, 8, 5, 3, 7, 8, 13, 6], 'angle': [10, 2, 1, 8, 3, 5, 1, 3, 6, 7], 
                    'spin': [10, 2, 1, 8, 5, 6, 4, 8, 9, 11], 'phase': [10, 2, 1, 8, 23, 44, 57, 21, 36, 8], 
                    'fuel': [100, 90, 80, 70, 60, 50, 40, 30, 20, 10], 'std_dev': [10, 2, 1, 8, 5, 6, 2, 1, 7, 5]})
df_2 = pd.DataFrame({'UNIT': ['seconds', 'meters per second', 'meters', 'degrees', 'radians per second', 'radians', 'liters', 'deviations'], 'VALUE': [1, 1, 1, 1, 1, 1, 1, 1]}, 
                      index=['time', 'speed', 'altitude', 'angle', 'spin', 'phase', 'fuel', 'std_dev'])
srs_1 = pd.Series({'Ohio': 35000, 'Texas': 71000, 'Oregon': 16000, 'Utah': 5000})
srs_2 = pd.Series({'Austin': 1500, 'Dayton': 2000, 'Portland': 3000, 'Salt Lake City': 400, 'Chicago':3465, 'Dallas':2300})
xmpldata = (df_1, df_2, srs_1, srs_2)

    
with open("xmpl1.pkl", "wb") as fl:
    pkl.dump(xmpldata, fl)

Then in a separate script i open it:

with open('xmpl1.pkl', 'rb') as f:
    pkl.load(f)

It seems to run smoothly, however the only thing that appears in my variable explorer is a Buffered Reader Object.

Advertisement

Answer

pkl.load returns the loaded object. Your code immediately discards it. You should assign in to a variable:

loaded = pkl.load(f)
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement