@@ -1456,24 +1456,15 @@ default value.
14561456
14571457 .. _indexing.lookup :
14581458
1459- Looking up values by index/column labels
1459+ The :meth: ` ~pandas.DataFrame.lookup ` method
14601460----------------------------------------
1461+ Sometimes you want to extract a set of values given a sequence of row labels
1462+ and column labels, and the ``lookup `` method allows for this and returns a
1463+ NumPy array. For instance:
14611464
1462- Sometimes you want to extract a set of values given a sequence of row labels
1463- and column labels, this can be achieved by ``pandas.factorize `` and NumPy indexing.
1464- For instance:
1465-
1466- .. ipython :: python
1467-
1468- df = pd.DataFrame({' col' : [" A" , " A" , " B" , " B" ],
1469- ' A' : [80 , 23 , np.nan, 22 ],
1470- ' B' : [80 , 55 , 76 , 67 ]})
1471- df
1472- idx, cols = pd.factorize(df[' col' ])
1473- df.reindex(cols, axis = 1 ).to_numpy()[np.arange(len (df)), idx]
1474-
1475- Formerly this could be achieved with the dedicated ``DataFrame.lookup `` method
1476- which was deprecated in version 1.2.0 and removed in version 2.0.0.
1465+ .. ipython :: python
1466+ dflookup = pd.DataFrame(np.random.rand(20 , 4 ), columns = [' A' , ' B' , ' C' , ' D' ])
1467+ dflookup.lookup(list (range (0 , 10 , 2 )), [' B' , ' C' , ' A' , ' B' , ' D' ])
14771468
14781469 .. _indexing.class :
14791470
0 commit comments