Вы забыли назначить вывод, но более быстрое векторизованное решение - преобразовать столбец в строку и добавить строки без apply
с f
строками:
def some_function():
df['important_column'] = [f'<b>{x}</b>' for x in df['important_column']]
#alternative1
df['important_column'] = '<b>' + df['important_column'].astype(str) + '</b>'
#alternative2
#df['important_column'] = df['important_column'].apply(lambda x: '<b>' + str(x) + '</b>')
#alternative3, thanks @Jon Clements
#df['important_column'] = df['important_column'].apply('<b>{}</b>?'.format)
return df.to_html()
EDIT:
df['important_column'] = [f'<b>{x}</b>' for x in df['important_column']]
print (df.to_html(escape=False))
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>important_column</th>
<th>dummy_column</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td><b>1</b></td>
<td>5</td>
</tr>
<tr>
<th>1</th>
<td><b>2</b></td>
<td>6</td>
</tr>
<tr>
<th>2</th>
<td><b>3</b></td>
<td>7</td>
</tr>
<tr>
<th>3</th>
<td><b>4</b></td>
<td>8</td>
</tr>
</tbody>
</table>
Задержка
df = pd.DataFrame({'important_column': [1,2,3,4],
'dummy_column': [5,6,7,8]})
df = pd.concat([df] * 10000, ignore_index=True)
In [213]: %timeit df['important_column'] = [f'<b>{x}</b>' for x in df['important_column']]
74 ms ± 22.2 ms per loop (mean ± std. dev. of 7 runs, 100 loops each)
In [214]: %timeit df['important_column'] = df['important_column'].apply(lambda x: '<b>' + str(x) + '</b>')
150 ms ± 7.75 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
In [216]: %timeit df['important_column'].apply('<b>{}</b>?'.format)
133 ms ± 238 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
In [217]: %timeit '<b>' + df['important_column'].astype(str) + '</b>'
266 ms ± 1.21 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)