【发布时间】:2014-08-20 00:46:32
【问题描述】:
当存在多级命名时,如何从 DataFrame 中选择特定列?
>>> x = pd.DataFrame({'instance':['first','first','first'],'foo':['a','b','c'],'bar':rand(3)})
>>> x = x.set_index(['instance','foo']).transpose()
>>> x.columns
MultiIndex
[(u'first', u'a'), (u'first', u'b'), (u'first', u'c')]
>>> x
instance first
foo a b c
bar 0.102885 0.937838 0.907467
(注意:这个问题是在 cmets 中向this SO question 提出的,并且 cmets 中也有一个答案。认为将其作为一个问题本身会很好。) em>
【问题讨论】: