Delete border from html table created using pandas

I am using a python script to display data on a web page. I used df.to_htmlto convert my data frame to HTML. However, by default it sets the border to 0. I tried to override it by creating my own CSS template, but it does not work.

Here is my pandas code:

ricSubscription.to_html(classes='mf')

Is there a parameter that I can pass to set the border to zero when making this call?

+6
source share
3 answers

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

You can simply do:

ricSubscription.to_html().replace('border="1"','border="0"')

Also, to answer specifically, it looks like you can't convey anything. border="1"looks hard coded:

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

+10

0.19.0 pandas 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/generated/pandas.DataFrame.to_html.html.

+5

If you want to use pd.Styler. You can do something like this:

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

All Articles