python
import pandas as pd
data = {
"case1": {
"aaa": 1222,
"bbb": 1333,
},
"case2": {
"ddd": 1444,
"ccc": 1555,
}
}
case1_df = pd.DataFrame(data["case1"], index=[0])
case2_df = pd.DataFrame(data["case2"], index=[0])
# 生成多级表头DF
df = pd.concat({"case1": case1_df, "case2": case2_df}, axis=1)
# case1_df = pd.DataFrame(data2["case1"], index=[0])
# case2_df = pd.DataFrame(data2["case2"], index=[0])
# df2 = pd.concat({"case1": case1_df, "case2": case2_df}, axis=1)
# df = df.append(df2)
# df.to_excel("111.xlsx")
# 读取多级表头数据
df2 = pd.read_excel("111.xlsx", header=[0, 1])
# 向原多级表头的excel追加数据
df = df2.append(df)
df.to_excel("111.xlsx")