【发布时间】:2017-02-01 18:59:08
【问题描述】:
从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 数据框中获取像这样的 stye:this 的 href 吗?
更新
我的模板如下所示:
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>
【问题讨论】:
-
你的模板是什么样的?
-
在 web 应用程序中使用 pandas 时,请注意线程安全问题:stackoverflow.com/questions/25782912/…
-
@dim 感谢您的帮助!...我更新了问题的状态
-
如何渲染模板?
tables是什么?是否包含来自linkify的返回值?还是在table?
标签: python html python-3.x pandas flask