代码比较简洁
df = pd.DataFrame({
"animal": ("horse", "horse", "dog", "dog"),
"color": ("black", "white", "grey", "black"),
"name": ("Blacky", "Wendy", "Rufus", "Catchy")
})
index = df.columns.to_list()
df = df.set_index(index)
df.to_excel("demo.xlsx")