我该如何从Julia加载Python的.pkl(pickle)文件?
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"
load_pickle("<文件路径>.pkl")
,它应该将其加载到一个Julia Dict
中。Pandas.jl
}}来读取.pkl
文件:julia> using Pandas
julia> df = read_pickle("<FILE_NAME>.pkl");
另外,您可以通过以下方式将其转换为DataFrames.DataFrame
对象:
julia> using DataFrames
julia> df1 = DataFrames.DataFrame(df);
然后,如果您检查每个对象的类型:
julia> typeof(df)
Pandas.DataFrame
julia> typeof(df1)
DataFrames.DataFrame