【发布时间】:2020-04-29 16:20:38
【问题描述】:
我正在尝试为 Plotly Dash webapp 创建一个表。
我想从数据框中的数据创建下表(两列表,一侧为列名,另一侧为值):
列名 |价值
我正在使用下面的逻辑,但它只是给了我一个包含一列的表,并将值和列名堆叠在同一列中。
return html.Table(
# Header
[html.Tr([html.Tr(col) for col in dataframe.columns])] +
# Body
[html.Td([
html.Tr(dataframe.iloc[i][col]) for col in dataframe.columns
]) for i in range(min(len(dataframe), max_rows))]
)
对于那些熟悉 html 的人来说,这是我想要做的:
<table>
<tr>
<td>Column Name:</td>
<td>Values:</td>
</tr>
</table>
@brokenfoot 我尝试使用您的示例,但它告诉我逗号是语法错误:
return html.Table(
[
html.Tr( [html.Td(col) for col in dataframe.columns
,html.Td(dataframe.iloc[i][col]) for col in dataframe.columns])
for i in range(min(len(dataframe), max_rows))
]
)
【问题讨论】:
标签: python plotly-dash