How to stop pandas.to_html() introducing newline ghost row?

Viewed 965

Here is a minimalist example of what seems to be a problem with pandas.to_html in pandas==0.25.1

I create a simple dataframe that, when converted to html, suffers from extraneous newline character padding.

df = pd.DataFrame()
>>> df['name']=['barney','frank']
>>> df['age'] = [4,5]
>>> df
     name  age
0  barney    4
1   frank    5
>>> df.to_html()

Seem innocent enough but we get..

<table border="1" class="dataframe">\n  <thead>\n    <tr style="text-align: right;">\n      <th></th>\n      <th>name</th>\n      <th>age</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>barney</td>\n      <td>4</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>frank</td>\n      <td>5</td>\n    </tr>\n  </tbody>\n</table>

What's with all the /n ?

0 Answers
Related