How can I load a python .pkl (pickle) file from Julia?
How to load python pickle from Julia?
Given that there are over 200 existing questions on Stackoverflow about python pickling, I think this is on-topic. –
Sturdivant
I don't you understand what I've written. seeking recommendations for packages is not! stackoverflow.com/help/on-topic –
Linzy
and now you need to give a minimal reproducible example of what you have tried and the errors you're facing –
Linzy
Here is a snippet to load in pickle files directly with PyCall:
using PyCall
py"""
import pickle
def load_pickle(fpath):
with open(fpath, "rb") as f:
data = pickle.load(f)
return data
"""
load_pickle = py"load_pickle"
Then use load_pickle("<path to file>.pkl")
and it should load it into a Julia Dict
.
Another way is to use Pandas.jl
to read the .pkl
file:
julia> using Pandas
julia> df = read_pickle("<FILE_NAME>.pkl");
Also, You can convert it to a DataFrames.DataFrame
object in this way:
julia> using DataFrames
julia> df1 = DataFrames.DataFrame(df);
Then if you check for the type of each object:
julia> typeof(df)
Pandas.DataFrame
julia> typeof(df1)
DataFrames.DataFrame
© 2022 - 2024 — McMap. All rights reserved.