1

I have a pandas data frame and there is a column which contains strings like these:

    Column B
    <a href="path_to_some_filea.txt" >value_of_a</a>
    <a href="path_to_some_fileb.txt" >value_of_b</a>

I converted the above pandas dataframe to html using to_html like this:

    df.to_html(index_names=False)

The converted html code replaces the <,> in the string with weird characters. The converted html for the specific column looks like this:

    &lt;a href="path_to_some_filea.txt" &gt;value_of_a&lt;/a&gt;
    &lt;a href="path_to_some_fileb.txt" &gt;value_of_b&lt;/a&gt;

Does anyone know why this is happening and how to fix this issue ?

1 Answer 1

5

You can set escape argument in df.to_html to False, to prevent special characters escaping:

    df.to_html(index_names=False, escape=False)

It is set to True by default and it convert the characters <, >, and & to HTML-safe sequences.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.