假设我有一个带有 MultiIndex 的 DataFrame,就像这样
In [88]: topic_word
Out[88]:
n p
topic_id token
0 functions 1 0.076923
layer 7 0.538462
layered 1 0.076923
module 1 0.076923
multi 1 0.076923
perceptron 1 0.076923
separable 1 0.076923
1 copy 1 0.200000
electromyograph 1 0.200000
physical 2 0.400000
techniques 1 0.200000
2 aw 1 0.125000
computed 1 0.125000
region 3 0.375000
regions 3 0.375000
3 autonomous 1 0.041667
diverse 1 0.041667
heterogeneity 1 0.041667
heterogeneous 4 0.166667
integrate 2 0.083333
如何将 MultiIndex 的内容插入到常规列中,以便可以像选择任何其他列一样选择它们?
topic_id token n p
0 0 functions 1 0.076923
1 0 layer 7 0.538462
2 0 layered 1 0.076923
3 0 module 1 0.076923
4 0 multi 1 0.076923
5 0 perceptron 1 0.076923
6 0 separable 1 0.076923
7 1 copy 1 0.200000
8 1 electromyograph 1 0.200000
9 1 physical 2 0.400000
10 1 techniques 1 0.200000
11 2 aw 1 0.125000
12 2 computed 1 0.125000
13 2 region 3 0.375000
14 2 regions 3 0.375000
15 3 autonomous 1 0.041667
16 3 diverse 1 0.041667
17 3 heterogeneity 1 0.041667
18 3 heterogeneous 4 0.166667
19 3 integrate 2 0.083333