You need to remove the column name:
df.rename_axis(None, axis=1).rename_axis('id', axis=0)
##if pd.__version__ == 0.24.0
#df.rename_axis([None], axis=1).rename_axis('id')
The problem is that 'summary'
is your column name. When there is no index name, the column name is placed directly above the index, which can be misleading:
import pandas as pd
df = pd.DataFrame([[1]*2]*4, columns=['A', 'B'])
df.columns.name = 'col_name'
print(df)
#col_name A B
#0 1 1
#1 1 1
#2 1 1
#3 1 1
When you then try to add an index name, it becomes clear that 'col_name'
was really the column name.
df.index.name = 'idx_name'
print(df)
#col_name A B
#idx_name
#0 1 1
#1 1 1
#2 1 1
#3 1 1
There is no ambiguity though: when you have an index name, the columns are raised one level, which allows you to distinguish between an index name and a column name.
df = pd.DataFrame([[1]*2]*4, columns=['A', 'B'])
df.index.name = 'idx_name'
print(df)
# A B
#idx_name
#0 1 1
#1 1 1
#2 1 1
#3 1 1
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…