python-3.x - 为什么在尝试获取数据分析报告时会出现 IndexError?
问题描述
我最近开始使用python。而且,我正在尝试使用 pandas_profiling 获取报告,但遇到了 IndexError。有人可以解释我如何调试这个吗?
数据有 30 个变量和大约 800,000 行。
到目前为止,我正在尝试将 csv 文件读入数据框并使用 pandas 分析对其进行分析。没有编写自定义代码[部分来自使用标准库和包。
提前致谢
import numpy as np
import pandas as pd
from pandas_profiling import ProfileReport
df_s = pd.read_csv(r'<file_path>')
ProfileReport(df_s)
Error below
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
343 method = get_real_method(obj, self.print_method)
344 if method is not None:
--> 345 return method()
346 return None
347 else:
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas_profiling\__init__.py in _repr_html_(self)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas_profiling\__init__.py in to_widgets(self)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas_profiling\report\presentation\flavours\widget\sequence.py in render(self)
95
96 elif self.sequence_type in ["tabs", "sections"]:
---> 97 widget = get_tabs(self.content["items"])
98 elif self.sequence_type == "accordion":
99 widget = get_accordion(self.content["items"])
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas_profiling\report\presentation\flavours\widget\sequence.py in get_tabs(items)
16 titles = []
17 for item in items:
---> 18 children.append(item.render())
19 titles.append(get_name(item))
20
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas_profiling\report\presentation\flavours\widget\sequence.py in render(self)
97 widget = get_tabs(self.content["items"])
98 elif self.sequence_type == "accordion":
---> 99 widget = get_accordion(self.content["items"])
100 elif self.sequence_type == "grid":
101 widget = get_row(self.content["items"])
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas_profiling\report\presentation\flavours\widget\sequence.py in get_accordion(items)
59 titles = []
60 for item in items:
---> 61 children.append(item.render())
62 titles.append(get_name(item))
63
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas_profiling\report\presentation\flavours\widget\preview.py in render(self)
9 else:
10 items = [self.content["top"]]
---> 11 return WidgetSequence(items, sequence_type="variable").render()
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas_profiling\report\presentation\flavours\widget\sequence.py in render(self)
75 elif self.sequence_type == "variable":
76 i1 = self.content["items"][0].render()
---> 77 i2 = self.content["items"][1].render()
78 toggle = widgets.ToggleButton(description="Toggle details")
79
IndexError: list index out of range
解决方案
我有同样的错误,然后我减少了 df_s 的数量并且它起作用了。你可以试一试。
例子:
ProfileReport(df_s[:10000])
推荐阅读
- scope - Pine 脚本变量范围
- facet - 使用 par() 将绘图与添加的线相结合
- powershell - 为什么在 Invoke-RestMethod 调用失败后 $_Exception 没有内容?
- javascript - 在不影响其子级的情况下转换父级 div
- linux - Client-Server进程互通
- syntax - 有没有一种(简单的)方法来修改某些特定编程语言的语法?
- python - 如何使用已编译的 Code 对象创建 Function 对象?
- azure - 在 Windows VM 中使用 VM 自定义扩展安装 Azure 文件时出现问题
- python - 如何确定一个点是否位于凹壳(Alpha 形状)内?
- python - Kivy - 从主类更新弹出窗口中的标签文本