@@ -1417,9 +1417,7 @@ class _LocIndexer(_LocationIndexer):
1417
1417
Selects a group of rows and columns by label(s) or a boolean array.
1418
1418
1419
1419
``.loc[]`` is primarily label based, but may also be used with a
1420
- boolean array. Note that if no row or column labels are specified
1421
- the labels will default to the integers 0 to n - 1, with n being
1422
- the number of rows/columns, respectively.
1420
+ boolean array.
1423
1421
1424
1422
Allowed inputs are:
1425
1423
@@ -1429,19 +1427,19 @@ class _LocIndexer(_LocationIndexer):
1429
1427
- A list or array of labels, e.g. ``['a', 'b', 'c']``.
1430
1428
- A slice object with labels, e.g. ``'a':'f'`` (note that contrary
1431
1429
to usual python slices, **both** the start and the stop are included!).
1432
- - A boolean array, e.g. [True, False, True].
1430
+ - A boolean array of the same length as the axis being sliced,
1431
+ e.g. ``[True, False, True]``.
1433
1432
- A ``callable`` function with one argument (the calling Series, DataFrame
1434
1433
or Panel) and that returns valid output for indexing (one of the above)
1435
1434
1436
- ``.loc`` will raise a ``KeyError`` when the items are not found.
1437
-
1438
1435
See more at :ref:`Selection by Label <indexing.label>`
1439
1436
1440
1437
See Also
1441
1438
--------
1442
- at : Selects a single value for a row/column label pair
1443
- iat : Selects a single value for a row/column pair by integer position
1444
- iloc : Selects group of rows and columns by integer position(s)
1439
+ DateFrame.at : Access a single value for a row/column label pair
1440
+ DateFrame.iat : Access a single value for a row/column pair by integer
1441
+ position
1442
+ DateFrame.iloc : Access group of rows and columns by integer position(s)
1445
1443
1446
1444
Examples
1447
1445
--------
@@ -1452,30 +1450,82 @@ class _LocIndexer(_LocationIndexer):
1452
1450
r0 12 2 3
1453
1451
r1 0 4 1
1454
1452
r2 10 20 30
1453
+
1454
+ Single label for row (note it would be faster to use ``DateFrame.at`` in
1455
+ this case)
1456
+
1455
1457
>>> df.loc['r1']
1456
1458
c0 0
1457
1459
c1 4
1458
1460
c2 1
1459
1461
Name: r1, dtype: int64
1462
+
1463
+
1464
+ Single label for row and column (note it would be faster to use
1465
+ ``DateFrame.at`` in this case)
1466
+
1467
+ >>> df.loc['r0', 'c1']
1468
+ 2
1469
+
1470
+
1471
+ A list of labels
1472
+
1460
1473
>>> df.loc[['r1', 'r2']]
1461
1474
c0 c1 c2
1462
1475
r1 0 4 1
1463
1476
r2 10 20 30
1464
- >>> df.loc['r0', 'c1']
1465
- 2
1477
+
1478
+ Slice with labels for row and single label for column. Note that
1479
+ contrary to usual python slices, both the start and the stop are
1480
+ included!
1481
+
1466
1482
>>> df.loc['r0':'r1', 'c0']
1467
1483
r0 12
1468
1484
r1 0
1469
1485
Name: c0, dtype: int64
1486
+
1487
+
1488
+ Boolean list with the same length as the row axis
1489
+
1470
1490
>>> df.loc[[False, False, True]]
1471
1491
c0 c1 c2
1472
1492
r2 10 20 30
1493
+
1494
+ Callable that returns valid output for indexing
1495
+
1473
1496
>>> df.loc[df['c1'] > 10]
1474
1497
c0 c1 c2
1475
1498
r2 10 20 30
1499
+
1500
+ Callable that returns valid output with column labels specified
1501
+
1476
1502
>>> df.loc[df['c1'] > 10, ['c0', 'c2']]
1477
1503
c0 c2
1478
1504
r2 10 30
1505
+
1506
+ Another example using integers for the index
1507
+
1508
+ >>> df = pd.DataFrame([[12, 2, 3], [0, 4, 1], [10, 20, 30]],
1509
+ ... index=[7, 8, 9], columns=['c0', 'c1', 'c2'])
1510
+ >>> df
1511
+ c0 c1 c2
1512
+ 7 12 2 3
1513
+ 8 0 4 1
1514
+ 9 10 20 30
1515
+
1516
+ Slice with integer labels for rows. Note that contrary to usual
1517
+ python slices, both the start and the stop are included!
1518
+
1519
+ >>> df.loc[7:9]
1520
+ c0 c1 c2
1521
+ 7 12 2 3
1522
+ 8 0 4 1
1523
+ 9 10 20 30
1524
+
1525
+ Raises
1526
+ ------
1527
+ KeyError:
1528
+ when items are not found
1479
1529
"""
1480
1530
1481
1531
_valid_types = ("labels (MUST BE IN THE INDEX), slices of labels (BOTH "
0 commit comments