Open
Description
df = pd.DataFrame([[1,2],[3,4]], index=pd.MultiIndex.from_product([['a'], [1,2]]), columns=pd.MultiIndex.from_product([['b'], [3,4]]))
df.to_html().split('\n')
['<table border="1" class="dataframe">',
' <thead>',
' <tr>',
' <th></th>',
' <th></th>',
' <th colspan="2" halign="left">b</th>',
' </tr>',
' <tr>',
' <th></th>',
' <th></th>',
' <th>3</th>',
' <th>4</th>',
' </tr>',
' </thead>',
' <tbody>',
' <tr>',
' <th rowspan="2" valign="top">a</th>',
' <th>1</th>',
' <td>1</td>',
' <td>2</td>',
' </tr>',
' <tr>',
' <th>2</th>',
' <td>3</td>',
' <td>4</td>',
' </tr>',
' </tbody>',
'</table>']
valign
is a deprecated HTML attribute and halign
is reported to be poorly supported even when it was not deprecated.
CSS solutions are recommended, but inline css like 'style="text-align:center;"' is not recommended as inline styles can break the more secure website CSPs (content security policies).
See here..
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/td