简体   繁体   English

pandas 数据框到 html 文件中的 ag-Grid 表

[英]pandas dataframe to ag-Grid table in html file

I'm trying to convert a Pandas DataFrame to an ag-Grid table using justpy package.我正在尝试使用justpy包将 Pandas DataFrame 转换为 ag-Grid 表。

However the linked page shows only how to run the page on localhost page.但是,链接页面仅显示如何在 localhost 页面上运行该页面。 In the other hand, they clearly state here that:另一方面,他们在这里明确指出:

Each component in JustPy also supports the to_html() method. JustPy 中的每个组件也支持 to_html to_html()方法。 It returns a string with the HTML representation of the element including all its child elements.它返回一个字符串,其中包含元素的 HTML 表示形式,包括其所有子元素。 You can think of it as the inverse of parse_html() .您可以将其视为parse_html()的倒数。

Bun unfortunately, when I try the to_html() for a webpage that contains an ag-Grid table it raises the following Exception:不幸的是,当我为包含 ag-Grid 表的网页尝试to_html()时,会引发以下异常:

AttributeError: 'AgGrid' object has no attribute 'to_html'

For instance this code works as excepted:例如,此代码作为例外工作:

import justpy as jp
import pandas as pd 

def grid_test():
    wp = jp.WebPage()
    d = jp.Div(text='Hello world!')
    wp.add(d)
    return wp
web_page = grid_test()
html = web_page.to_html()
with open(path + "my_table.html", "w") as f:
    f.write(html)

And this is the code raising the excption:这是引发异常的代码:

import justpy as jp
import pandas as pd 

def grid_test():
    wp = jp.WebPage()
    my_df_ca.jp.ag_grid(a=wp)  # a=wp adds the grid to WebPage wp
    return wp
web_page = grid_test()
html = web_page.to_html()
with open(path + "my_table.html", "w") as f:
    f.write(html)

实际上,我发现最适合我需要的工具是ipyaggrid ,它允许从数据框构建高度灵活的 html 表并使用.export_html(build=True)导出它们

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM