2024-06-16 13:24:02 发布
网友
我有熊猫数据框,正在使用“df_styled=df.style.apply(…)”方法方便地设置数据框中的值的样式(在Jupyter笔记本中)。 但是,在使用Dash Plotly dashboard时,我无法显示此样式输出
有人能提出什么建议吗
我尝试了df_styled.render()方法,但这在Dash dashboard上显示了我的样式化数据框的字符串表示,而不是HTML输出(正如我在Jupyter笔记本中看到的)
与直接使用Pandas的样式化组件不同,我建议使用以下组件
下面是一个示例代码
mytable = dash_table.DataTable( id='table1', columns=[{"name": i, "id": i,'type':'numeric', 'format': {'specifier': ',.0f'}} if i not in ['phone_number'] else {"name": i, "id": i} for i in df.columns], data=df.to_dict('records'), style_as_list_view=True, style_cell={'padding': '2px'}, page_action='none', style_table={'height': '600px', 'overflowY': 'auto'}, style_cell_conditional=[ { 'if': {'column_id': 'phone_number'}, 'textAlign': 'center' }, ], style_data_conditional=[ { 'if': {'row_index': 0}, 'backgroundColor': '#FFF2CC', }, ], style_header={ 'backgroundColor': 'white', 'fontWeight': 'bold', 'textAlign': 'center' }, )
与直接使用Pandas的样式化组件不同,我建议使用以下组件
下面是一个示例代码
相关问题 更多 >
编程相关推荐