在 google-colab 中,pandas.read_pickle() 不适用于 pickle5

In google-colab pandas.read_pickle() is not working on pickle5

我使用 pd.to_pickle() 从我的计算机制作了一个数据帧的 pickle 文件,我无法在 colab 中读取它。它给出错误 ValueError: unsupported pickle protocol: 5。请给出解决方案

您需要先安装pickle5,使用:

!pip install pickle5

然后,

#Import the library
import pickle5 as pickle

path = 'path_to_pickle5'

with open(path, "rb") as dt:
  df = pickle.load(dt)