Say I have a dataframe with string values that contains some HTML
my_dict = {"a":{"content":"""
<p>list of important things</p>
<ul>
<li>c</li>
<li>d</li>
</ul>
"""}}
df = pd.DataFrame.from_dict(my_dict,orient='index')
The result is to be expected:
I'd like to export the dataframe as HTML such that my HTML string works inside the table cells.
What I've tried
I'm aware of DataFrame.to_html(escape=False), which produces:
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>content</th>
</tr>
</thead>
<tbody>
<tr>
<th>a</th>
<td>\n<p>list of important things</p>\n<ul>\n<li>c</li>\n<li>d</li>\n</ul>\n</td>
</tr>
</tbody>
</table>
which looks wrong:
because that HTML has a literal \\n, so I think the method has taken the repr of the string value when inserting it into the HTML conversion of the dataset.
I know I could get away replacing the scaped \\n into \n again, which looks like it should:
But I'd like to know if there is some way to tell pandas to insert the literal string values of the dataframe into the HTML, not the repr ones. I don't understand half of the kwargs for .to_html(), so I don't know if that's possible.


