Description
Let 'b' be a large dataframe with MulitiIndex.
I pull the 4th block based on the 1st level of the index, and I got the block fine.
a = b.ix[b.index.levels[0][4]]
Then I printed the index of the block, which also seemed fine, code and result as follows:
print a.index
sequence attribute
4 count
price
quantity
and when I pull values, they seemed fine too:
a.index.values
array([(4L, 'count'), (4L, 'price'), (4L, 'quantity')], dtype=object)
but when I looked at it in a different way, things didn't make much sense:
a.index
MultiIndex(levels=[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, ...], [u'count', u'price', u'quantity']],
labels=[[4, 4, 4], [0, 1, 2]],
names=[u'sequence', u'attribute'])
and when I pull the first level from the index of the block, I got:
a.index.levels[0]
Int64Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, ...], dtype='int64')
Which is not the
Int64Index([4], dtype='int64')
I anticipated.
Of course I can
pd.MultiIndex.from_tuples(a.index.values)
and create the thing I am expecting, but this is a pain in the ass. Any solutions? Thanks!