0

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]

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.