You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/source/indexing.rst
+79-14
Original file line number
Diff line number
Diff line change
@@ -79,6 +79,10 @@ of multi-axis indexing.
79
79
- A slice object with labels ``'a':'f'``, (note that contrary to usual python
80
80
slices, **both** the start and the stop are included!)
81
81
- A boolean array
82
+
- A ``callable`` function with one argument (the calling Series, DataFrame or Panel) and
83
+
that returns valid output for indexing (one of the above)
84
+
85
+
.. versionadded:: 0.18.1
82
86
83
87
See more at :ref:`Selection by Label <indexing.label>`
84
88
@@ -93,6 +97,10 @@ of multi-axis indexing.
93
97
- A list or array of integers ``[4, 3, 0]``
94
98
- A slice object with ints ``1:7``
95
99
- A boolean array
100
+
- A ``callable`` function with one argument (the calling Series, DataFrame or Panel) and
101
+
that returns valid output for indexing (one of the above)
102
+
103
+
.. versionadded:: 0.18.1
96
104
97
105
See more at :ref:`Selection by Position <indexing.integer>`
98
106
@@ -110,6 +118,8 @@ of multi-axis indexing.
110
118
See more at :ref:`Advanced Indexing <advanced>` and :ref:`Advanced
111
119
Hierarchical <advanced.advanced_hierarchical>`.
112
120
121
+
- ``.loc``, ``.iloc``, ``.ix`` and also ``[]`` indexing can accept a ``callable`` as indexer. See more at :ref:`Selection By Callable <indexing.callable>`.
122
+
113
123
Getting values from an object with multi-axes selection uses the following
114
124
notation (using ``.loc`` as an example, but applies to ``.iloc`` and ``.ix`` as
115
125
well). Any of the axes accessors may be the null slice ``:``. Axes left out of
@@ -317,6 +327,7 @@ The ``.loc`` attribute is the primary access method. The following are valid inp
317
327
- A list or array of labels ``['a', 'b', 'c']``
318
328
- A slice object with labels ``'a':'f'`` (note that contrary to usual python slices, **both** the start and the stop are included!)
319
329
- A boolean array
330
+
- A ``callable``, see :ref:`Selection By Callable <indexing.callable>`
320
331
321
332
.. ipython:: python
322
333
@@ -340,13 +351,13 @@ With a DataFrame
340
351
index=list('abcdef'),
341
352
columns=list('ABCD'))
342
353
df1
343
-
df1.loc[['a','b','d'],:]
354
+
df1.loc[['a','b','d'],:]
344
355
345
356
Accessing via label slices
346
357
347
358
.. ipython:: python
348
359
349
-
df1.loc['d':,'A':'C']
360
+
df1.loc['d':,'A':'C']
350
361
351
362
For getting a cross section using a label (equiv to ``df.xs('a')``)
352
363
@@ -358,15 +369,15 @@ For getting values with a boolean array
358
369
359
370
.. ipython:: python
360
371
361
-
df1.loc['a']>0
362
-
df1.loc[:,df1.loc['a']>0]
372
+
df1.loc['a']>0
373
+
df1.loc[:,df1.loc['a']>0]
363
374
364
375
For getting a value explicitly (equiv to deprecated ``df.get_value('a','A')``)
365
376
366
377
.. ipython:: python
367
378
368
379
# this is also equivalent to ``df1.at['a','A']``
369
-
df1.loc['a','A']
380
+
df1.loc['a','A']
370
381
371
382
.. _indexing.integer:
372
383
@@ -387,6 +398,7 @@ The ``.iloc`` attribute is the primary access method. The following are valid in
387
398
- A list or array of integers ``[4, 3, 0]``
388
399
- A slice object with ints ``1:7``
389
400
- A boolean array
401
+
- A ``callable``, see :ref:`Selection By Callable <indexing.callable>`
390
402
391
403
.. ipython:: python
392
404
@@ -416,26 +428,26 @@ Select via integer slicing
416
428
.. ipython:: python
417
429
418
430
df1.iloc[:3]
419
-
df1.iloc[1:5,2:4]
431
+
df1.iloc[1:5,2:4]
420
432
421
433
Select via integer list
422
434
423
435
.. ipython:: python
424
436
425
-
df1.iloc[[1,3,5],[1,3]]
437
+
df1.iloc[[1,3, 5],[1,3]]
426
438
427
439
.. ipython:: python
428
440
429
-
df1.iloc[1:3,:]
441
+
df1.iloc[1:3,:]
430
442
431
443
.. ipython:: python
432
444
433
-
df1.iloc[:,1:3]
445
+
df1.iloc[:,1:3]
434
446
435
447
.. ipython:: python
436
448
437
449
# this is also equivalent to ``df1.iat[1,1]``
438
-
df1.iloc[1,1]
450
+
df1.iloc[1,1]
439
451
440
452
For getting a cross section using an integer position (equiv to ``df.xs(1)``)
0 commit comments