【发布时间】:2019-06-27 18:53:23
【问题描述】:
考虑以下pd.DataFrame
df_index = pd.MultiIndex.from_product([['foo','bar'],['one','two','three']])
df = pd.DataFrame(np.random.randint(0,10,size=18, dtype='int').reshape((-1,6)), columns=df_index)
print(df)
foo bar
one two three one two three
0 7 3 8 3 6 0
1 2 5 9 4 3 6
2 4 2 6 6 4 5
我希望将'foo' 和其中的所有子索引设置为索引。我怎样才能做到这一点?我正在努力解决'set_index'和pd.IndexSlice,但仍然无法找到解决方案
【问题讨论】:
标签: python pandas numpy multi-index