本文介绍了无法加载包含腌制数据的文件-Python .npy I/O的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用np.save()将数据帧和矩阵另存为.npy文件,然后使用np.load()读取它们,但出现以下错误:
I am trying to save a dataframe and a matrix as .npy files with np.save() and then read them using np.load() but I get the following error:
File "/Users/sofiafarina/opt/anaconda3/lib/python3.7/site-packages/numpy/lib/npyio.py", line 457, in load
raise ValueError("Cannot load file containing pickled data "
ValueError: Cannot load file containing pickled data when allow_pickle=False
即使我写allow_pickle = True,我也会收到一个错误:
Even if I write allow_pickle=True I get an error:
File "/Users/sofiafarina/opt/anaconda3/lib/python3.7/site-packages/numpy/lib/npyio.py", line 463, in load
"Failed to interpret file %s as a pickle" % repr(file))
OSError: Failed to interpret file 'finaldf_p_85_12.npy' as a pickle
那么我该如何从python脚本中保存df,然后将其加载到另一个脚本中呢?我应该使用其他功能吗?谢谢!
So how could I save a df from a python script and then load it in another one? Should I use other functions?Thank you!
推荐答案
我使用下面的语法加载了 .npy
文件,该文件起作用了.
I used the syntax below to load the .npy
file and it worked.
np.load("finaldf_p_85_12.npy",allow_pickle=True)
我认为您需要添加 allow_pickle = True
参数.
I think you need to add allow_pickle=True
parameter.
这篇关于无法加载包含腌制数据的文件-Python .npy I/O的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!