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(index = False) not dropping df.columns.name in the html output #26126

Closed
benpap24 opened this issue Apr 17, 2019 · 1 comment
Closed

Comments

@benpap24
Copy link

benpap24 commented Apr 17, 2019

df = pd.DataFrame({'A': [1,2],
                   'B': [3,4]})

df.columns.name = 'Test'

df.to_html(index = False)

#Output

<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th>Test</th>
      <th>A</th>
      <th>B</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th></th>
      <td>1</td>
      <td>3</td>
    </tr>
    <tr>
      <th></th>
      <td>2</td>
      <td>4</td>
    </tr>
  </tbody>
</table>

Problem description

I recently updated one of my projects from 0.23.4 to 0.24.1 and the html output of df.to_html(index = False) changed when there is a column name (ie. one generated from when you create a pivot table).

Previously, df.to_html(index = False) would drop the column name, however now it creates an empty column with the column name.

I've also confirmed reverting to 0.23.4 fixes the issue.

Expected Output

<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th>A</th>
      <th>B</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td>3</td>
    </tr>
    <tr>
      <td>2</td>
      <td>4</td>
    </tr>
  </tbody>
</table>

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.7.0.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 142 Stepping 10, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.24.1
pytest: 3.8.0
pip: 10.0.1
setuptools: 40.2.0
Cython: 0.28.5
numpy: 1.16.0
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 6.5.0
sphinx: 1.7.9
patsy: 0.5.1
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 3.0.0
openpyxl: 2.5.6
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.1.0
lxml.etree: 4.3.0
bs4: 4.6.3
html5lib: 1.0.1
sqlalchemy: 1.2.11
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

@benpap24 benpap24 changed the title to_html(index = False) not dropping df.column.name in the html output to_html(index = False) not dropping df.columns.name in the html output Apr 17, 2019
@WillAyd
Copy link
Member

WillAyd commented Apr 18, 2019

This is intentional. See #23788

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants