微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用HTML格式时pandas_profiling TypeError

如何解决使用HTML格式时pandas_profiling TypeError

我遵循pandas_profiling文档脚本,但是总是会出现此问题。 我的数据集是sklearn的波士顿。

我有报告,但是没有html版本的功能

profile2 = ProfileReport(data,title="Relatório DATASET -data-",html={'style': {'full_width': True}},sort="None")

下面的图像引用此代码

 from pandas_profiling import ProfileReport    
 profile = ProfileReport(data,title='Pandas Profiling Report',explorative=True)

[![在此处输入图片描述] [1]] [1]

我的pandas_profiling版本 [![在此处输入图片描述] [2]] [2]

如果我使用此代码,则没有以上相关问题:

profile = ProfileReport (data)

更新: 卸载以前的版本并获得了新版本(2.9.0),但是会发生此问题:

  Summarize dataset: 75%
21/28 [00:07<00:02,2.84it/s,Get scatter matrix]

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
C:\ProgramData\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:

C:\ProgramData\Anaconda3\lib\site-packages\pandas_profiling\profile_report.py in _repr_html_(self)
    407     def _repr_html_(self):
    408         """The ipython notebook widgets user interface gets called by the jupyter notebook."""
--> 409         self.to_notebook_iframe()
    410 
    411     def __repr__(self):

C:\ProgramData\Anaconda3\lib\site-packages\pandas_profiling\profile_report.py in to_notebook_iframe(self)
    387         with warnings.catch_warnings():
    388             warnings.simplefilter("ignore")
--> 389             display(get_notebook_iframe(self))
    390 
    391     def to_widgets(self):

C:\ProgramData\Anaconda3\lib\site-packages\pandas_profiling\report\presentation\flavours\widget\notebook.py in get_notebook_iframe(profile)
     63         output = get_notebook_iframe_src(profile)
     64     elif attribute == "srcdoc":
---> 65         output = get_notebook_iframe_srcdoc(profile)
     66     else:
     67         raise ValueError(

C:\ProgramData\Anaconda3\lib\site-packages\pandas_profiling\report\presentation\flavours\widget\notebook.py in get_notebook_iframe_srcdoc(profile)
     21     width = config["notebook"]["iframe"]["width"].get(str)
     22     height = config["notebook"]["iframe"]["height"].get(str)
---> 23     src = html.escape(profile.to_html())
     24 
     25     iframe = f'<iframe width="{width}" height="{height}" srcdoc="{src}" frameborder="0" allowfullscreen></iframe>'

C:\ProgramData\Anaconda3\lib\site-packages\pandas_profiling\profile_report.py in to_html(self)
    357 
    358         """
--> 359         return self.html
    360 
    361     def to_json(self) -> str:

C:\ProgramData\Anaconda3\lib\site-packages\pandas_profiling\profile_report.py in html(self)
    177     def html(self):
    178         if self._html is None:
--> 179             self._html = self._render_html()
    180         return self._html
    181 

C:\ProgramData\Anaconda3\lib\site-packages\pandas_profiling\profile_report.py in _render_html(self)
    284         from pandas_profiling.report.presentation.flavours import HTMLReport
    285 
--> 286         report = self.report
    287 
    288         disable_progress_bar = not config["progress_bar"].get(bool)

C:\ProgramData\Anaconda3\lib\site-packages\pandas_profiling\profile_report.py in report(self)
    171     def report(self):
    172         if self._report is None:
--> 173             self._report = get_report_structure(self.description_set)
    174         return self._report
    175 

C:\ProgramData\Anaconda3\lib\site-packages\pandas_profiling\profile_report.py in description_set(self)
    152     def description_set(self):
    153         if self._description_set is None:
--> 154             self._description_set = describe_df(self.title,self.df,self._sample)
    155         return self._description_set
    156 

C:\ProgramData\Anaconda3\lib\site-packages\pandas_profiling\model\describe.py in describe(title,df,sample)
    100         # Scatter matrix
    101         pbar.set_postfix_str("Get scatter matrix")
--> 102         scatter_matrix = get_scatter_matrix(df,variables)
    103         pbar.update()
    104 

C:\ProgramData\Anaconda3\lib\site-packages\pandas_profiling\model\summary.py in get_scatter_matrix(df,variables)
    696             for y in continuous_variables:
    697                 if x in continuous_variables:
--> 698                     scatter_matrix[x][y] = scatter_pairwise(df[x],df[y],x,y)
    699     else:
    700         scatter_matrix = {}

C:\ProgramData\Anaconda3\lib\contextlib.py in inner(*args,**kwds)
     71         @wraps(func)
     72         def inner(*args,**kwds):
---> 73             with self._recreate_cm():
     74                 return func(*args,**kwds)
     75         return inner

C:\ProgramData\Anaconda3\lib\contextlib.py in __enter__(self)
    110         del self.args,self.kwds,self.func
    111         try:
--> 112             return next(self.gen)
    113         except stopiteration:
    114             raise RuntimeError("generator didn't yield") from None

C:\ProgramData\Anaconda3\lib\site-packages\pandas_profiling\visualisation\context.py in manage_matplotlib_context()
     77         register_matplotlib_converters()
     78         matplotlib.rcParams.update(customrcParams)
---> 79         sns.set_style(style="white")
     80         yield
     81     finally:

AttributeError: module 'seaborn' has no attribute 'set_style'

解决方法

解决方案是取消安装/重新安装Anaconda和pandas配置文件。可能是Paul H在评论中建议的某个版本问题。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。