Skip to content

Commit eaa45cf

Browse files
authored
DOC: Add behavior for Index argument in DataFrame.loc (#38109)
1 parent 7070aae commit eaa45cf

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pandas/core/indexing.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,11 @@ def loc(self) -> "_LocIndexer":
259259
e.g. ``[True, False, True]``.
260260
- An alignable boolean Series. The index of the key will be aligned before
261261
masking.
262+
- An alignable Index. The Index of the returned selection will be the input.
262263
- A ``callable`` function with one argument (the calling Series or
263264
DataFrame) and that returns valid output for indexing (one of the above)
264265
265-
See more at :ref:`Selection by Label <indexing.label>`
266+
See more at :ref:`Selection by Label <indexing.label>`.
266267
267268
Raises
268269
------
@@ -332,6 +333,14 @@ def loc(self) -> "_LocIndexer":
332333
max_speed shield
333334
sidewinder 7 8
334335
336+
Index (same behavior as ``df.reindex``)
337+
338+
>>> df.loc[pd.Index(["cobra", "viper"], name="foo")]
339+
max_speed shield
340+
foo
341+
cobra 1 2
342+
viper 4 5
343+
335344
Conditional that returns a boolean Series
336345
337346
>>> df.loc[df['shield'] > 6]

0 commit comments

Comments
 (0)