ModuleNotFoundError: 使用Metaflow时找不到模块’pandas.core.indexes.numeric’

huangapple go评论57阅读模式
英文:

ModuleNotFoundError: No module named 'pandas.core.indexes.numeric' using Metaflow

问题

I used Metaflow to load a Dataframe. It was successfully unpickled from the artifact store, but when I try to view its index using df.index, I get an error that says ModuleNotFoundError: No module named 'pandas.core.indexes.numeric'. Why?

我使用Metaflow加载了一个DataFrame。它成功地从存储库中反序列化,但当我尝试使用df.index查看其索引时,我收到一个错误消息,显示ModuleNotFoundError: No module named 'pandas.core.indexes.numeric'。为什么会出现这个错误?

I've looked at other answers with similar error messages here and here, which say that this is caused by trying to unpickle a dataframe with older versions of Pandas. However, my error is slightly different, and it is not fixed by upgrading Pandas (pip install pandas -U).

我查看了其他具有类似错误消息的答案这里这里,它们说这是由于尝试使用较旧版本的Pandas反序列化DataFrame引起的。然而,我的错误略有不同,升级Pandas(pip install pandas -U)并不能解决它。

英文:

I used Metaflow to load a Dataframe. It was successfully unpickled from the artifact store, but when I try to view its index using df.index, I get an error that says ModuleNotFoundError: No module named 'pandas.core.indexes.numeric'. Why?

I've looked at other answers with similar error messages here and here, which say that this is caused by trying to unpickle a dataframe with older versions of Pandas. However, my error is slightly different, and it is not fixed by upgrading Pandas (pip install pandas -U).

答案1

得分: 25

这个问题是由新版Pandas 2.0.0发布导致的,它破坏了与Pandas 1.x的向后兼容性,尽管我在发布说明中没有看到这方面的记录。解决方法是将Pandas降级到1.x系列:pip install "pandas<2.0.0"

英文:

This issue is caused by the new Pandas 2.0.0 release breaking backwards compatibility with Pandas 1.x, although I don't see this documented in the release notes. The solution is to downgrade pandas to the 1.x series: pip install &quot;pandas&lt;2.0.0&quot;

答案2

得分: 17

尝试使用pandas.read_pickle()方法来加载文件,而不是使用pickle模块:

import pandas as pd

df = pd.read_pickle("file.pkl")

Pandas方法应该提供与读取旧文件的兼容性,并且“仅在对象使用to_pickle进行序列化后,才能保证向后兼容到pandas 0.20.3。” 我在使用pandas-1.x进行的测试显示它也可以读取一些使用pickle模块编写的文件。

英文:

Try using the pandas.read_pickle() method to load the file instead of the pickle module:

import pandas as pd

df = pd.read_pickle(&quot;file.pkl&quot;)

The pandas method should provide compatibility to read older files, and "is only guaranteed to be backwards compatible to pandas 0.20.3 provided the object was serialized with to_pickle." My tests with pandas-1.x show it can also read some files written from the pickle module too.

答案3

得分: 0

尝试使用 pd.compat.pickle_compat.load(),这在我的情况下是唯一的解决方案:

import pandas as pd

df = pd.compat.pickle_compat.load('file.pkl')
英文:

Try using pd.compat.pickle_compat.load() as that was only solution in my case:

import pandas as pd

df = pd.compat.pickle_compat.load(&#39;file.pkl&#39;) 

答案4

得分: 0

不知道为什么这个方法有效,但是joblib.load在读取 pickle 文件时出现了与“模块名 'pandas.core.indexes.numeric'”相同的错误。然后我安装了prefectsimple_salesforce,不知何故,现在它可以正常工作了... 不太确定为什么,但我认为值得一提。

英文:

So i dont know why this works but joblib.load was failing to read the pickle with the same error "module named 'pandas.core.indexes.numeric'" then i installed prefect and simple_salesforce and some how it now works... not sure why but i think worth mentioning

huangapple
  • 本文由 发表于 2023年4月7日 03:52:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75953279.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定