Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to_html(col_space=<int>) does not set min-width style correctly. #25941

Closed
simonjayhawkins opened this issue Mar 31, 2019 · 0 comments

Comments

@simonjayhawkins
Copy link
Member

commented Mar 31, 2019

Code Sample, a copy-pastable example if possible

import pandas as pd
import pandas.util.testing as tm
df = pd.DataFrame(index = tm.makeMultiIndex())
print(df.to_html(col_space=100))
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th style="min-width: 100;"></th>
      <th style="min-width: 100;"></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th rowspan="2" valign="top"style="min-width: 100;">foo</th>
      <th style="min-width: 100;">1</th>
    </tr>
    <tr>
      <th style="min-width: 100;">2</th>
    </tr>
    <tr>
      <th rowspan="2" valign="top"style="min-width: 100;">bar</th>
      <th style="min-width: 100;">1</th>
    </tr>
    <tr>
      <th style="min-width: 100;">2</th>
    </tr>
  </tbody>
</table>

Problem description

The col_space parameter expects an int..

col_space : int, optional
The minimum width of each column.

it should be either px of % for HTML but this raises an error if you try.

print(df.to_html(col_space='100px'))

gives TypeError: '>' not supported between instances of 'str' and 'int'

The <th style="min-width: 100;"> is also applied needlessly to the <th> tags within <tbody>

Expected Output

<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th style="min-width: 100px;"></th>
      <th style="min-width: 100px;"></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th rowspan="2" valign="top">foo</th>
      <th>1</th>
    </tr>
    <tr>
      <th>2</th>
    </tr>
    <tr>
      <th rowspan="2" valign="top">bar</th>
      <th>1</th>
    </tr>
    <tr>
      <th>2</th>
    </tr>
  </tbody>
</table>

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.