Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从通过pandas创建的html表中删除边框_Python_Html_Pandas - Fatal编程技术网

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

Python 从通过pandas创建的html表中删除边框,python,html,pandas,Python,Html,Pandas,我正在使用python脚本在网页上显示dataframe。我使用df.to_html将数据帧转换为html。但是,默认情况下,它将边框设置为0。我试图通过定制css模板来覆盖它,但没有成功 这是我的密码: ricSubscription.to_html(classes='mf') 在进行此调用时,是否可以传递一个参数来将边框设置为零?to_html()生成… 你可以这样做: ricSubscription.to_html().replace('border="1"','border="0"')

我正在使用python脚本在网页上显示dataframe。我使用
df.to_html
将数据帧转换为html。但是,默认情况下,它将边框设置为0。我试图通过定制css模板来覆盖它,但没有成功

这是我的密码:

ricSubscription.to_html(classes='mf')
在进行此调用时,是否可以传递一个参数来将边框设置为零?

to_html()
生成

你可以这样做:

ricSubscription.to_html().replace('border="1"','border="0"')
另外,具体地说,似乎没有任何东西可以通过
border=“1”
似乎是硬编码的:


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

  • 全局:
    pd.options.html.border=0
  • 本地:
    to_html(border=0)

  • 更新2019-07-11:

    根据@Hagbard的评论,我最初的全球解决方案已被弃用,取而代之的是以下内容:
    pd.options.display.html.border=0



    文档:

    如果您愿意,请使用
    pd.Styler
    。你可以这样做:

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

    似乎没有,您可以解析html并替换
    边框
    值,但这确实让Google为css覆盖感到乏味。这对你应该有帮助。这很有效!谢谢replace方法可以用来替换由to_html()创建的任何内容吗?这有点奇怪,border的值是这样硬编码的。@HimanshuGupta
    df.to_html()
    返回一个
    unicode
    对象,因此您可以使用
    find
    replace
    strip
    上部
    下部
    ,就像你想要一个字符串并替换你想要的任何东西一样。使用你对全局设置的回答,我得到以下警告:“html.border已被弃用,请改用display.html.border(目前两者完全相同)”。因此,从现在起,“pd.options.display.html.border=0”就起作用了。@Hagbard-如果你想用新版本发布答案,请这样做。否则,我会用新版本更新我的。谢谢。如果你更新你的答案对我来说没关系。谢谢。:)