Skip to content

Commit 7292c17

Browse files
committed
1 parent 12b6572 commit 7292c17

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

doc/source/user_guide/indexing.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,7 @@ Looking up values by index/column labels
14621462
Sometimes you want to extract a set of values given a sequence of row labels
14631463
and column labels, this can be achieved by ``pandas.factorize`` and NumPy indexing.
14641464

1465-
For heterogeneous column types, we subset columns to avoid unnecessary numpy conversions:
1465+
For heterogeneous column types, we subset columns to avoid unnecessary NumPy conversions:
14661466

14671467
.. code-block:: python
14681468
@@ -1478,12 +1478,13 @@ For heterogeneous column types, we subset columns to avoid unnecessary numpy con
14781478
result = values[flat_index]
14791479
return result
14801480
1481-
For homogeneous column types, it is fastest to skip column subsetting and go directly to numpy:
1481+
For homogeneous column types, it is fastest to skip column subsetting and go directly to NumPy:
14821482

14831483
.. code-block:: python
14841484
14851485
def pd_lookup_hom(df, row_labels, col_labels):
14861486
rows = df.index.get_indexer(row_labels)
1487+
df = df.loc[:, sorted(set(col_labels))]
14871488
cols = df.columns.get_indexer(col_labels)
14881489
result = df.to_numpy()[rows, cols]
14891490
return result

0 commit comments

Comments
 (0)