栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何格式化Pandas数据框的IPython html显示?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何格式化Pandas数据框的IPython html显示?

HTML接收html数据的自定义字符串。没有人禁止您传入带有自定义CSS样式的样式标签

.dataframe
(该
to_html
方法将其添加到表中)。

因此,最简单的解决方案是仅添加样式并将其与的输出连接

df.to_html

style = '<style>.dataframe td { text-align: right; }</style>'HTML( style + df.to_html( formatters=frmt ) )

但我建议为Dataframe定义一个自定义类,因为这将更改笔记本中所有表的样式(样式为“全局”)。

style = '<style>.right_aligned_df td { text-align: right; }</style>'HTML(style + df.to_html(formatters=frmt, classes='right_aligned_df'))

您还可以在前面的单元格之一中定义样式,然后只需设置方法的

classes
参数即可
to_html

# Some cell at the begining of the notebookIn [2]: HTML('''<style>         .right_aligned_df td { text-align: right; }         .left_aligned_df td { text-align: right; }         .pink_df { background-color: pink; }     </style>''')...# Much later in your notebookIn [66]: HTML(df.to_html(classes='pink_df'))


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/610689.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号