我有一個示例資料框,如下所示:
894385426F4B81 8932F0978F4B80 89434C3243F4B81 899AD7554F4B80
metric 82.557 227.063 9.193 91.205
但是當我生成一個帶有繪圖破折號的表格時:
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)
])
我看到這個表帶有這個索引名稱:
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(),否則情節破折號不會列印“公制”
uj5u.com熱心網友回復:
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/313002.html
