gpt4 book ai didi

python - 在 jupyter notebook 中使用 pandas 分析时如何修复此错误

转载 作者:行者123 更新时间:2023-12-01 23:05:49 26 4
gpt4 key购买 nike

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

IndexError: only integers, slices (:), ellipsis (...),numpy.newaxis (None) and integer or boolean arrays are validindices.

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}})

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

最佳答案

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

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

如果您得到与我在 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.py 中的weighted_median 函数

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

关于python - 在 jupyter notebook 中使用 pandas 分析时如何修复此错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70908256/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com