来自 pandas 的 JS 数据表 [英] JS dataTables from pandas

查看:36
本文介绍了来自 pandas 的 JS 数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 Pandas 数据帧与数据表一起使用.我无法弄清楚如何在没有 id 的情况下初始化表.

I want to use pandas dataFrames with dataTables. I cannot figure out how to initialize the table without an id.

当我调用df.to_html()时,有没有办法在table标签中设置id?

Is there any way to set the id in the table tag when I call df.to_html()?

推荐答案

你可以试试这个:

df.to_html(classes = 'my_class" id = "my_id')

基本上就像 SQL 注入.
Pandas 的 to_html 函数在类周围使用双引号.您可以使用单引号来定义 classes 参数,并在其中放置双引号以结束 pandas 的类.然后在您的 id 名称周围加上双引号,但让 pandas 为您关闭这些双引号.输出如下:

It's like a SQL injection basically.
Pandas' to_html function uses double quotes around the class. You can use single quotes to define the classes argument, and put double quotes inside them to end pandas' class. Then put opening double quotes around your id name but let pandas' close those double quotes for you. The output will be the following:

'<table border="1" class="dataframe my_class" id = "my_id">...'

希望有所帮助.

这篇关于来自 pandas 的 JS 数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆