HTML破折号表 [英] Html dash table

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

问题描述

我正在尝试使用破折号创建html表

I am trying to use dash to create a html table

我的数据框如下所示:

   Cap non-cap
0   A   a
1   B   b
2   C   c
3   D   d
4   E   e
..
26  Z   z

我想显示html表,就像数据帧,但没有0-26索引。
结构为

I want to display an html table just like the dataframe, but without the 0 - 26 index. The structure is

{'Cap' : ['A', 'B', 'C',....], 'non-Cap' : ['a','b','c',...]}

我尝试过:

return html.Table(
  [html.Tr([html.Th(col) for col in dataframe.columns])] +
  [html.Tr([
    html.Td(dataframe.iloc[i][col]) for col in dataframe.columns
  ]) for i in range(min(len(dataframe), max_rows))]  
)


推荐答案

import dash
import dash_html_components as html
import pandas as pd

data = {'Cap' : ['A', 'B', 'C', ], 'non-Cap' : ['a','b','c', ]}
df = pd.DataFrame(data)

def generate_table(dataframe, max_rows=26):
    return html.Table(
        # Header
        [html.Tr([html.Th(col) for col in dataframe.columns]) ] +
        # Body
        [html.Tr([
            html.Td(dataframe.iloc[i][col]) for col in dataframe.columns
        ]) for i in range(min(len(dataframe), max_rows))]
    )

app = dash.Dash(__name__, )

app.layout = html.Div(children=[
    html.H4(children='StackOverflow - Html dash table'),
    generate_table(df)
])

if __name__ == '__main__':
    app.run_server(debug=True)

这篇关于HTML破折号表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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