【发布时间】:2016-08-17 14:35:01
【问题描述】:
我希望可以使用 Pandas DataFrame 中的 to_html() 直接格式化索引(列)并输出到 HTML?
类似:
df = DataFrame([[1, 2]], index=['a'], columns=['A', 'B'])
print(df.to_html(formatters={
'index': lambda elem: '<a href="example.com/{}">{}</a>'.format(elem, elem)}, escape=False))
这不起作用。我没有得到链接。
我想我需要做一些类似的事情
dfc = df.copy()
dfc.index = ['<a href="example.com/{}">{}</a>'.format(i, i) for i in df.index]
print(dfc.to_html(escape=False))
【问题讨论】: