Here I the data I try to save as a “pickle file”
JavaScript
x
17
17
1
import pandas as pd
2
import pickle as pkl
3
4
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],
5
'altitude': [10, 2, 1, 8, 5, 3, 7, 8, 13, 6], 'angle': [10, 2, 1, 8, 3, 5, 1, 3, 6, 7],
6
'spin': [10, 2, 1, 8, 5, 6, 4, 8, 9, 11], 'phase': [10, 2, 1, 8, 23, 44, 57, 21, 36, 8],
7
'fuel': [100, 90, 80, 70, 60, 50, 40, 30, 20, 10], 'std_dev': [10, 2, 1, 8, 5, 6, 2, 1, 7, 5]})
8
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]},
9
index=['time', 'speed', 'altitude', 'angle', 'spin', 'phase', 'fuel', 'std_dev'])
10
srs_1 = pd.Series({'Ohio': 35000, 'Texas': 71000, 'Oregon': 16000, 'Utah': 5000})
11
srs_2 = pd.Series({'Austin': 1500, 'Dayton': 2000, 'Portland': 3000, 'Salt Lake City': 400, 'Chicago':3465, 'Dallas':2300})
12
xmpldata = (df_1, df_2, srs_1, srs_2)
13
14
15
with open("xmpl1.pkl", "wb") as fl:
16
pkl.dump(xmpldata, fl)
17
Then in a separate script i open it:
JavaScript
1
3
1
with open('xmpl1.pkl', 'rb') as f:
2
pkl.load(f)
3
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:
JavaScript
1
2
1
loaded = pkl.load(f)
2