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

When transposing a datetime index without time and using to_html, time is added to column titles. #10640

Open
benlester opened this issue Jul 20, 2015 · 2 comments
Labels
Bug IO HTML read_html, to_html, Styler.apply, Styler.applymap

Comments

@benlester
Copy link

As outlined in my stackoverflow question, pandas to_html() doesn't behave consistently with a datetime index after being transposed.

A simple example:

import pandas as pd
import numpy as np

df = pd.DataFrame(np.random.randn(5, 5), columns = ['a', 'b', 'c', 'd', 'e'], index = ["2015-01-05","2015-01-04","2015-01-03","2015-01-02","2015-01-01"])
df.index = pd.to_datetime(df.index)

Then df.to_html() outputs:

<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>a</th>
      <th>b</th>
      <th>c</th>
      <th>d</th>
      <th>e</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>2015-01-05</th>
      <td>-0.025414</td>
      <td>0.001241</td>
      <td>-0.110182</td>
      <td>0.101301</td>
      <td>0.904187</td>
    </tr>
    <tr>
      <th>2015-01-04</th>
      <td>-0.113769</td>
      <td>1.490484</td>
      <td>0.386378</td>
      <td>0.152447</td>
      <td>0.440914</td>
    </tr>
    <tr>
      <th>2015-01-03</th>
      <td>-0.807287</td>
      <td>0.161482</td>
      <td>-0.255942</td>
      <td>0.041502</td>
      <td>-0.314685</td>
    </tr>
    <tr>
      <th>2015-01-02</th>
      <td>-0.849947</td>
      <td>0.600126</td>
      <td>-1.516112</td>
      <td>-0.571000</td>
      <td>0.013668</td>
    </tr>
    <tr>
      <th>2015-01-01</th>
      <td>-0.421461</td>
      <td>-0.287318</td>
      <td>-1.411263</td>
      <td>-0.088717</td>
      <td>-0.823639</td>
    </tr>
  </tbody>
</table>

Where as df.T.to_html() adds time (00:00:00) to the column titles:

<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>2015-01-05 00:00:00</th>
      <th>2015-01-04 00:00:00</th>
      <th>2015-01-03 00:00:00</th>
      <th>2015-01-02 00:00:00</th>
      <th>2015-01-01 00:00:00</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>a</th>
      <td>-0.025414</td>
      <td>-0.113769</td>
      <td>-0.807287</td>
      <td>-0.849947</td>
      <td>-0.421461</td>
    </tr>
    <tr>
      <th>b</th>
      <td>0.001241</td>
      <td>1.490484</td>
      <td>0.161482</td>
      <td>0.600126</td>
      <td>-0.287318</td>
    </tr>
    <tr>
      <th>c</th>
      <td>-0.110182</td>
      <td>0.386378</td>
      <td>-0.255942</td>
      <td>-1.516112</td>
      <td>-1.411263</td>
    </tr>
    <tr>
      <th>d</th>
      <td>0.101301</td>
      <td>0.152447</td>
      <td>0.041502</td>
      <td>-0.571000</td>
      <td>-0.088717</td>
    </tr>
    <tr>
      <th>e</th>
      <td>0.904187</td>
      <td>0.440914</td>
      <td>-0.314685</td>
      <td>0.013668</td>
      <td>-0.823639</td>
    </tr>
  </tbody>
</table>

This behaviour is inconsistent.

A remedy was found by EdChum on stackoverflow.

@jreback
Copy link
Contributor

jreback commented Jul 20, 2015

yeh, these should be the same. The SO soln is ok, but this actually is a bug in that the formatters are not applied to the columns.

@jreback jreback added Bug Output-Formatting __repr__ of pandas objects, to_string IO HTML read_html, to_html, Styler.apply, Styler.applymap labels Jul 20, 2015
@jreback jreback added this to the Next Major Release milestone Jul 20, 2015
@jreback
Copy link
Contributor

jreback commented Jul 20, 2015

pull-requests welcome!

@mroeschke mroeschke removed the Output-Formatting __repr__ of pandas objects, to_string label Apr 18, 2021
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
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

No branches or pull requests

3 participants