If you want to format columns separatelly - without joining values from two columns - then you can use formatters in to_html()
You had to use also escape=False if you want to put HTML in column. Normally it converts < > to > <
BTW: I had to also set 'display.max_colwidth' because it was truncating text in column.
import pandas as pd
df = pd.DataFrame({'url':[
'https://stackoverflow.com',
'https://httpbin.org',
'https://toscrape.com',
]})
pd.set_option('display.max_colwidth', -1)
result = df.to_html(formatters={'url':lambda x:f'<a href="{x}">{x}</a>'}, escape=False)
print(result)
Result:
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>url</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td><a href="https://stackoverflow.com">https://stackoverflow.com</a></td>
</tr>
<tr>
<th>1</th>
<td><a href="https://httpbin.org">https://httpbin.org</a></td>
</tr>
<tr>
<th>2</th>
<td><a href="https://toscrape.com">https://toscrape.com</a></td>
</tr>
</tbody>
</table>
But if you want to create links using values from two columns then create new column in DataFrame.
Eventually you would have to format all in template (without using to_html)
df = pd.DataFrame({
'url':[
'https://stackoverflow.com',
'https://httpbin.org',
'https://toscrape.com',
],
'name':[
'Ask question',
'Test requests',
'Learn scraping'
]
})
and
<table>
{% for row in dt.iterrows() %}
<tr><td><a href="{{ row['url'] }}">{{ row['name'] }}</a></td></tr>
{% endfor %}
</table>
<a></a>. Other method would need internal{% for %}and{% if %}to convert every value in template - so it would be more complex.formatters=- I never used it but maybe it could convert values in column.