如何处理'numpy.generic'对象的'<属性'dtype'错误?

安装 pypfopt 和 u-numpy 后,dataframe.info()命令显示此错误。

TypeError: Cannot interpret '<attribute 'dtype' of 'numpy.generic' objects>' as a data type

回答

我碰巧混合了我的版本,今天我遇到了这个问题。我设法解决了它。jupyter 中的两个代码都给了我一个错误:TypeError: Cannot interpret '<attribute 'dtype' of 'numpy.generic' objects>' as a data type

df.info() 
df.categorical_column_name.value_counts().plot.bar()

我收到错误:TypeError:无法将 'numpy.generic' objects>' 的 '<attribute 'dtype' 解释为数据类型

这就是我修复它的方式

jyputer 内部:检查 numpy 版本:

import numpy as np
print(np.__version__)

升级:

!pip3 install numpy --upgrade

内部命令行检查 numpy 版本:python

import numpy
print(numpy.__version__)

如果版本不一样,选择是否升级/降级: 升级:

$pip install numpy --upgrade

降级只需指定版本

如果安装了python环境:转到正确的文件夹:检查安装的版本:

$pipenv --version
$pipenv --version

要验证您是否为该文件夹安装了 pip 环境: 在您的终端上转到该文件夹​​并键入:

如果有pipenv,它将显示版本,如果没有,则不会。

检查 numpy 版本

$python
>>> import numpy
#prints the version
>>> print(numpy__version__)

要升级版本:

>>>exit()

#安装最新版本不要指定版本

$pipenv install numpy

#如果要降级指定版本

$pipenv install numpy=version_type

对熊猫做同样的事情。请注意,如果您在 jupyter notebook 上的 pandas 环境为 1.2.3,请使用 pandas 升级 !pip install pandas==1.2.3 或 !pip install pandas --upgrade --user

请注意,如果命令给您一个错误,请始终在命令末尾包含 --user。

要使用 miniconda 创建新环境并安装更新的软件包,请点击链接 [https://pandas.pydata.org/pandas-docs/stable/getting_started/install.html][1]

从终端窗口运行以下命令:

  1. conda create -n name_of_my_env python 这将创建一个仅安装 Python 的最小环境。把你自己放在这个环境中运行:

source activate name_of_my_env 在 Windows 上命令是: 2. activate name_of_my_env

所需的最后一步是安装熊猫。这可以通过以下命令完成:

conda install pandas 要安装特定的 Pandas 版本:

  1. 畅达安装熊猫=0.20.3

我更喜欢使用最新版本的pandas 1.2.3

但是,第一种方法应该可以解决您的问题。始终重新启动您的笔记本,我关闭它并重新打开它。

我会留下来看看你是否赢了。但这将解决您的问题。该问题是由 numpy 和 pandas [1] 的版本引起的:https : //pandas.pydata.org/pandas-docs/stable/getting_started/install.html


以上是如何处理'numpy.generic'对象的'&lt;属性'dtype'错误?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>