如何使用 plotly dash 删除数据帧索引名称

How to get rid of dataframe index name with plotly dash

我有一个示例数据框,如下所示:

                894385426F4B81  8932F0978F4B80  89434C3243F4B81  899AD7554F4B80
metric          82.557         227.063           9.193          91.205

但是当我生成带有 plotly dash 的 table 时:

def generate_table(dataframe, max_rows=10):
    return html.Table([
        html.Thead(
            html.Tr( [html.Th(col) for col in dataframe.columns])
            
        ),
        html.Tbody([
            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([
    html.H4(children='table name'),
    generate_table(output)
])

我看到这个 table 有这个索引名称:

index          894385426F4B81  8932F0978F4B80  89434C3243F4B81  899AD7554F4B80
metric         82.557           227.06299999999996   9.193     91.205

拔头发把名字去掉index

对于数据框本身这是有效的,这意味着我在我的终端中看到了没有 index:

的数据框
output = output.rename_axis(None, axis=0)

我也试过:

output = output.rename_axis('', axis=1)
output = output.index.set_names([''])
output.columns.name = None
output.index.name = None

没有任何帮助!

顺便说一句,我需要使用 output = output.reset_index(),否则 plotly dash 不会打印“metric”

reset_index 自动添加 index 作为列名。如果不需要显示,将index列重命名为reset_index后的空字符串:

output.reset_index().rename(columns={'index': ''})

           894385426F4B81  8932F0978F4B80  89434C3243F4B81  899AD7554F4B80
0  metric          82.557         227.063            9.193          91.205