当存在多级命名时,如何从数据帧中选择特定列?你知道吗
>>> 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
(注:这个问题是在this SO question的评论中提出的,评论中也有答案。我觉得把它作为一个问题来讨论会很好。)
这正是多索引切片器的用途,请参见docshere
相关问题 更多 >
编程相关推荐