使用 MultiIndex 创建 DataFrame

Create a DataFrame with a MultiIndex

我想制作如下所示的 DataFrame 并将其导出到 excel。我有我输入的所有“-”的所有可用数据。我想知道将什么数据结构传递给 pd.Dataframe() 来制作这样的 table。

想知道如何pandas读取这些数据结构形成DataFrame。

idx = pd.MultiIndex.from_product([['Zara', 'LV', 'Roots'],
                                  ['Orders', 'GMV', 'AOV']],
                                 names=['Brand', 'Metric'])
col = ['Yesterday', 'Yesterday-1', 'Yesterday-7', 'Thirty day average']

df = pd.DataFrame('-', idx, col)
df

Jupyter 屏幕截图

df.to_excel('test.xlsx')

Mac 数字屏幕截图