Reputation: 3211
File in question has lines like this when opened with Notepad++:
€X Neural Networksq .€]q (X ClassificationqKX Team1 winq]q(X Team1qX Team2qe]q(X
Team1_rankqX
Team2_rankqX Diff1q X Diff2q
e}q(hcpandas.core.indexes.base
_new_Index
qcpandas.core.indexes.base
Index
q
etc. There are a lot of symbols that aren't shown above in the pkl file.
Below are the codes I've tried to read/parse the file into something readable:
With pickle:
import pickle; pickle.HIGHEST_PROTOCOL
with open(r"somefile.pkl", 'rb') as f:
data = pickle.load(f)
print (data)
With pandas:
import pandas as pd
up_df = pd.read_pickle(r"somefile.pkl")
print (up_df)
In both cases, I get a str
object that only writes 'Neural Network'
My somefile.pkl
is 63kb in size and obviously has bytecode? (guessing it is) in it. How do I go about converting it to something readable?
Upvotes: 1
Views: 478
Reputation: 101
Maybe the pickle file has multiple objects appended to it. Try something like -
objects = []
with open(filename, 'rb') as f:
data = pickle.load(f)
while True:
try:
objects.append(pickle.load(filename))
except EOFError:
break
Refer to How to read pickle file?
Upvotes: 0