从通过pandas创建的html表中删除边框

Him*_*pta 7 html python pandas

我正在使用python脚本在网页上显示数据框.我曾经df.to_html将我的数据帧转换为HTML.但是,默认情况下,它将边框设置为0.我尝试通过自定义css模板覆盖它,但它不起作用.

这是我的熊猫代码:

ricSubscription.to_html(classes='mf')
Run Code Online (Sandbox Code Playgroud)

在进行此调用时,是否有可以传递的参数将边框设置为零?

Eri*_*elt 12

to_html() 生成 <table border="1" class="dataframe">...

你可以这样做:

ricSubscription.to_html().replace('border="1"','border="0"')
Run Code Online (Sandbox Code Playgroud)

另外,要具体回答,似乎没有任何东西可以通过.border="1"似乎是硬编码的:

https://github.com/pydata/pandas/blob/e4cb0f8a6cbb5f0c89b24783baa44326e4b2cccb/pandas/core/format.py#L893


elP*_*tor 6

从0.19.0版开始,to_html()可以通过两种方式更改熊猫边框:

  1. 全球范围内: pd.options.html.border = 0
  2. 本地: to_html(border = 0)


更新2019-07-11:

根据@Hagbard的评论,不赞成使用我的原始全局解决方案,而推荐使用以下解决方案: pd.options.display.html.border = 0


文件:https//pandas.pydata.org/pandas-docs/stable/genic/pandas.DataFrame.to_html.html


Aji*_*jit 5

如果您想使用pd.Styler. 你可以这样做:

ricSubscription.style.set_table_attributes(
    'style="border-collapse:collapse"'
).set_table_styles([
    # Rest of styles
]).render()
Run Code Online (Sandbox Code Playgroud)