I am using a python script to display dataframe on a webpage. I used df.to_html
to convert my dataframe to HTML. However, by default, it sets the border to 0. I tried overriding it by having a custom css template but it didn't work.
Here is my pandas code:
ricSubscription.to_html(classes='mf')
Is there a parameter I can pass to set the border to zero while making this call?
Table with no outside border. Note: you can use “border: none;” or “border: 0px;”. Either way it results in the outside border being removed from your table.
This is a Default behavior of the table cells that there is some space between their Borders. To remove this space we can use the CSS border-collapsing Property. This Property is used to set the borders of the cell present inside the table and tells whether these cells will share a common border or not.
Go to Table Tools >Design > Table Styles > Borders, and then click the border option that you want to change. , and then click the borders that you want to delete.
to_html()
generates <table border="1" class="dataframe">...
You could just do:
ricSubscription.to_html().replace('border="1"','border="0"')
Also, to answer specifically, there does not appear to be anything you can pass. border="1"
appears to be hardcoded:
https://github.com/pydata/pandas/blob/e4cb0f8a6cbb5f0c89b24783baa44326e4b2cccb/pandas/core/format.py#L893
As of version 0.19.0, pandas to_html()
borders can be changed in two ways:
pd.options.html.border = 0
to_html(border = 0)
UPDATE 2019-07-11:
Per @Hagbard's comment, my original global solution has been deprecated in favor of the following:
pd.options.display.html.border = 0
Docs: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_html.html
If you are would like use pd.Styler
. You could do something like this :
ricSubscription.style.set_table_attributes(
'style="border-collapse:collapse"'
).set_table_styles([
# Rest of styles
]).render()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With