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 · 4 comments · Fixed by #26012
Closed

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

simonjayhawkins opened this issue Mar 31, 2019 · 4 comments · Fixed by #26012
Labels
Bug IO HTML read_html, to_html, Styler.apply, Styler.applymap
Milestone

Comments

@simonjayhawkins
Copy link
Member

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]

@jschendel jschendel added Bug IO HTML read_html, to_html, Styler.apply, Styler.applymap labels Apr 3, 2019
@jreback jreback added this to the 0.25.0 milestone Apr 6, 2019
@jreback jreback modified the milestones: 0.25.0, Contributions Welcome Apr 20, 2019
@jreback jreback modified the milestones: Contributions Welcome, 0.25.0 Apr 28, 2019
@questglobal-bom
Copy link

questglobal-bom commented Oct 10, 2019

col_space changes width of all columns. Is there a way to change width of a specific column only?

@simonjayhawkins
Copy link
Member Author

would probably need to update col_space to take a list or dict. could probably reuse some code used for the formatters parameter.

This request is likely to get lost in a closed issue. Can you raise a new issue.

@questglobal-bom
Copy link

Sure. Raised issue #28917.

@questglobal-bom
Copy link

Any update on how to increase col_space for specific columns only?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO HTML read_html, to_html, Styler.apply, Styler.applymap
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants