如何创建一个熊猫"链接" (href)风格?

时间:2016-09-23 20:13:51

标签: python html python-3.x pandas flask

documentation我意识到可以在pandas数据帧上创建样式。但是,我想知道是否可以创建链接样式。到目前为止,这是我尝试过的:

def linkify(data_frame_col):
 list_words = ['<a href="http://this_is_url_{}">{}</a>'.format(a,a) for a in data_frame_col]
 return list_words

问题在于,当我将pandas数据框架可视化为烧瓶网站时,我得到以下样式:

['<a href="http://this_is_url_hi">hi</a>',
 '<a href="http://this_is_url_quick fox brown">quick fox brown</a>',
 '<a href="http://this_is_url_fall apart">fall apart</a>',
 '<a href="http://this_is_url_hi">hi</a>',
 '<a href="http://this_is_url_no">no</a>']

而不是链接。想知道如何在pandas数据框中获得像这样的hyes:this吗?

更新

我的模板如下所示:

view.html:

<!doctype html>
<title>title</title>
<link rel=stylesheet type=text/css href="{{ url_for('static', filename='style.css') }}">
<div class=page>
  <h1>Title</h1>
  {% for table in tables %}
    <h2>{{titles[loop.index]}}</h2>
    {{ table|safe }}
  {% endfor %}
</div>

1 个答案:

答案 0 :(得分:1)

您可以使用IPython的display.HTML类型

from IPython.display import HTML
import pandas as pd

df = pd.DataFrame(['<a href="http://example.com">example.com</a>'])
HTML(df.to_html(escape=False))