繁体   English   中英

在 jupyter 笔记本中使用 pandas 分析时如何修复此错误

[英]How to fix this error while using pandas profiling in jupyter notebook

每次我在不同的数据集中使用 pandas 分析时,笔记本都会向我显示此错误。

IndexError:只有整数、切片 ( : )、省略号 ( ... )、numpy.newaxis ( None ) 和 integer 或 boolean arrays 是有效索引。

import pandas as pd

df = pd.read_csv('H:\DATA Sets\cereal.csv')

from pandas_profiling import ProfileReport

profile = ProfileReport(df,title='cereal-eda',html={'style' : {'full_width':True}})

使用的数据集 - cereal.csv 来自 kaggle https://www.kaggle.com/crawford/80-cereals

编辑:已经发布了一个 PR 来解决这个问题。 使用 Pandas 1.4.[01] 似乎是个问题在 pandas-profiling 的 github 上查看这个问题

我认为发生错误是因为 Numpy 以 pandas-profiling 模块之一使用的方式弃用了索引 arrays。

如果你得到相同的回溯我得到这个错误发生在pandas_profiling.model.pandas.utils_pandas的地方,你应该能够通过改变来解决这个问题:

w_median = data[weights == np.max(weights)][0]

w_median = data[np.where(weights == np.max(weights))][0]

$(YOUR_VIRTUAL_ENVIRONMENT_OR_PYTHON_DIR)/lib/python$(PYVERSION)/site-packages/pandas-profiling/model/pandas/utils_pandas.pyweighted_median function

(pandas-profiling 版本 3.1.0 的第 13 行)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM