Skip to content

pandas.DataFrame.to_html() without table border and tr style #22692

Closed
@norok2

Description

@norok2

The following code produces HTML code for the corresponding table:

import pandas as pd
import numpy as np

df = pd.DataFrame(data=np.arange(3 * 4).reshape(3, 4))
df.to_html(classes=None, border=None, justify=None)

Specifically, you get:

<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
    ...

However, both border and style tags are actually visualization details that should be left for the CSS. The expected behavior should be that the produced HTML should be:

<table>
  <thead>
    <tr>
    ...

Besides the problem that there is no way of getting to a clean HTML, this is contradicting the Zen of Python n.2 https://www.python.org/dev/peps/pep-0020/ , where Explicit is better than implicit..

If the default output is something of values for the majority of pandas users, the default values for classes, border and justify should be: classes='dataframe' (or classes=('dataframe',)), border=1, justify='right'.

(Just tested on the master branch).

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIO HTMLread_html, to_html, Styler.apply, Styler.applymap

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions