【问题标题】:How to set the default Styler for a pandas DataFrame's _repr_html method?如何为 pandas DataFrame _repr_html_ 方法设置默认样式?
【发布时间】:2019-12-17 21:39:41
【问题描述】:

我有一个带有 url 列的 pandas DataFrame,我编写了以下格式化程序以将其作为链接显示在我的笔记本中:

def make_clickable(val):
    # target _blank to open new window
    return '<a target="_blank" href="{}">{}</a>'.format(val, val)
all_data.style.format({'url': make_clickable})

这很好地打印出我的表格,其中的 url 可以点击,但我真正想要做的是让这种样式作为该框架的默认样式持续存在,以便它用于_repr_html 我的数据框(及其切片)在同一个笔记本中。

有人知道这是否可能吗?

【问题讨论】:

    标签: python pandas jupyter-notebook jupyter pandas-styles


    【解决方案1】:

    据我所知,无法注册默认样式。我们覆盖了_repr_html_,替换了clickable_urls 参数。

                table_id=None,
                render_links=render_links,
            )
    

    https://github.com/pandas-dev/pandas/blob/c23649143781c658f792e8f7a5b4368ed01f719c/pandas/core/frame.py

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-26
      • 1970-01-01
      • 2011-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多