Reputation: 4807
I have a multiindex pandas data frame with data as following:
dataMyDF.ix[0:3]
dataMyDF
col1 col2 col3 col4 col5
W W 8.0 29.0 4.0 0.291155
P I 8.0 29.0 7.0 0.108057
N D 2.0 14.0 16.0 0.247355
where col1 through col5 are the index and data is the values. The multi index can be seen as:
shape.index[0]
(u'W', u'W', 8.0, 29.0, 4.0)
How do I extract data from dataMyDF:
i.e I want to do something like:
indexArr = [(W, W, 8.0, 29.0, 4.0), (N, D, 2.0, 14.0, 16.0)]
dataMyDF[indexArr]
to get [0.291155, 0.247355]
Upvotes: 0
Views: 728
Reputation: 76917
Using loc
In [1062]: df.loc[indexArr]
Out[1062]:
dataMyDF
col1 col2 col3 col4 col5
W W 8.0 29.0 4.0 0.291155
N D 2.0 14.0 16.0 0.247355
In [1063]: df.loc[indexArr].values
Out[1063]:
array([[ 0.291155],
[ 0.247355]])
.ix
inplace of .loc
works fine too.
Upvotes: 1