- 尽量保证pandas与numpy版本和原始生成pkl文件时的版本一致,如果生成pkl文件与读取pkl文件是在一个环境内,则掠过此步
import pandas as pd
import numpy as np
print("Pandas version:", pd.__version__)
print("NumPy version:", np.__version__)
- 加载pkl的类文件,比如我的是:
class Patient_ICU(object):
def __init__(self, admissions, demographics, core, dsnotes, radnotes):
self.admissions = admissions
self.demographics = demographics
self.core = core
self.dsnotes = dsnotes
self.radnotes = radnotes
- 开始读取文件,有以下几种读取方式:
filepath = "patient.pkl"
with open(filepath, 'rb') as input:
outdata = pickle.load(input)
from joblib import load
outdata = load(filepath)
import pandas as pd
outdata = pd.read_pickle(filepath)