2.18 The lookup() Method

Sometimes you want to extract a set of values given a sequence of row labels and column labels, and the lookup method allows for this and returns a numpy array. For instance,

In [1]: dflookup = pd.DataFrame(np.random.rand(20,4), columns = ['A','B','C','D'])

In [2]: dflookup
Out[2]: 
         A       B       C       D
0   0.2370  0.0076  0.0198  0.3131
1   0.0995  0.1952  0.2073  0.1649
2   0.7119  0.0321  0.1974  0.9646
3   0.5739  0.6992  0.9746  0.6544
..     ...     ...     ...     ...
16  0.0485  0.2681  0.5177  0.5486
17  0.4593  0.3095  0.2639  0.1575
18  0.9564  0.2689  0.9122  0.0495
19  0.5330  0.6987  0.4216  0.6982

[20 rows x 4 columns]

In [3]: dflookup.lookup(list(range(0,10,2)), ['B','C','A','B','D'])
Out[3]: array([ 0.0076,  0.1974,  0.2609,  0.0776,  0.5951])