擅长:python、mysql、java
<p>对于在python 3.8中使用协议5将数据帧保存到pickle文件并需要将其加载到仅支持协议4的python 3.6中的pandas用户(我正在查看您的<strong>google colab</strong>):</p>
<pre><code>!pip3 install pickle5
import pickle5 as pickle
with open(path_to_protocol5, "rb") as fh:
data = pickle.load(fh)
</code></pre>
<p>还可以从Python3.6保存到protocol-4 pickle中</p>
<pre><code>data.to_pickle(path_to_protocol4)
</code></pre>
<p>更新:如果从stable-baselines3加载模型时遇到此问题:</p>
<pre><code>!pip install --upgrade --quiet cloudpickle pickle5
from stable_baselines3 import PPO
# restart kernel if in jupyter notebook
# Might not need this dict in all cases
custom_objects = {
"lr_schedule": lambda x: .003,
"clip_range": lambda x: .02
}
model = PPO.load("path/to/model.zip", custom_objects=custom_objects)
</code></pre>
<p>2021年5月31日使用env进行测试:</p>
<pre><code>cloudpickle: 1.6.0
pickle5: 0.0.11
stable-baselines3: 1.0
</code></pre>
<p>参考:<a href="https://brainsteam.co.uk/2021/01/14/pickle-5-madness-with-mlflow/" rel="noreferrer">https://brainsteam.co.uk/2021/01/14/pickle-5-madness-with-mlflow/</a></p>