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

ENH: to_html improvement #4987

Closed
alefnula opened this issue Sep 25, 2013 · 4 comments
Closed

ENH: to_html improvement #4987

alefnula opened this issue Sep 25, 2013 · 4 comments
Labels
IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string
Milestone

Comments

@alefnula
Copy link
Contributor

I know that the whitespace doesn't meter in HTML but this is really a strange behaviour:

>>> df = pd.read_html(
             'http://en.wikipedia.org/wiki/Vancouver',
             match='Municipality', header=0
         )[0]
>>> df
0         Country         Municipality   NaN
1         Ukraine               Odessa  1944
2           Japan             Yokohama  1965
3  United Kingdom  Edinburgh[198][199]  1978
4           China       Guangzhou[200]  1985
5   United States          Los Angeles  1986
6     South Korea                Seoul  2007
>>> df.iat[3, 0]
'China'
>>> df.iat[4, 0]
'United States'
>>> df.iat[5, 1]
'Seoul'

Which is all fine, but if i try to convert it to HTML I get a really funky looking data :)

>>> print(df.to_html(index=False))
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th>Country</th>
      <th>Municipality</th>
      <th>nan</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>        Ukraine</td>
      <td>              Odessa</td>
      <td> 1944</td>
    </tr>
    <tr>
      <td>          Japan</td>
      <td>            Yokohama</td>
      <td> 1965</td>
    </tr>
    <tr>
      <td> United Kingdom</td>
      <td> Edinburgh[198][199]</td>
      <td> 1978</td>
    </tr>
    <tr>
      <td>          China</td>
      <td>      Guangzhou[200]</td>
      <td> 1985</td>
    </tr>
    <tr>
      <td>  United States</td>
      <td>         Los Angeles</td>
      <td> 1986</td>
    </tr>
    <tr>
      <td>    South Korea</td>
      <td>               Seoul</td>
      <td> 2007</td>
    </tr>
  </tbody>
</table>

And also, if I specify explicitly the classes why does it always adds the dataframe class? Shouldn't the classes override the default dataframe class?

@cpcloud
Copy link
Member

cpcloud commented Sep 25, 2013

Looks like it's trying to right align using whitespace. Not sure why it's doing that.... Sigh, templates are getting more and more attractive...

@alefnula
Copy link
Contributor Author

@cpcloud I can try to clean that up if you're not already working on this?

@cpcloud
Copy link
Member

cpcloud commented Sep 26, 2013

Nope. Please do :)

@jreback
Copy link
Contributor

jreback commented Mar 6, 2015

closed by #9285

@jreback jreback closed this as completed Mar 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO HTML read_html, to_html, Styler.apply, Styler.applymap Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
3 participants