Skip to content

Commit 78f342c

Browse files
committed
Add examples of setting values with loc
1 parent a3238d9 commit 78f342c

File tree

1 file changed

+42
-5
lines changed

1 file changed

+42
-5
lines changed

pandas/core/indexing.py

+42-5
Original file line numberDiff line numberDiff line change
@@ -1436,10 +1436,12 @@ class _LocIndexer(_LocationIndexer):
14361436
14371437
See Also
14381438
--------
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)
1439+
DateFrame.at
1440+
Access a single value for a row/column label pair
1441+
DateFrame.iat
1442+
Access a single value for a row/column pair by integer position
1443+
DateFrame.iloc
1444+
Access group of rows and columns by integer position(s)
14431445
14441446
Examples
14451447
--------
@@ -1482,7 +1484,6 @@ class _LocIndexer(_LocationIndexer):
14821484
r1 0
14831485
Name: c0, dtype: int64
14841486
1485-
14861487
Boolean list with the same length as the row axis
14871488
14881489
>>> df.loc[[False, False, True]]
@@ -1501,6 +1502,42 @@ class _LocIndexer(_LocationIndexer):
15011502
c0 c2
15021503
r2 10 30
15031504
1505+
Set value for all items matching the list of labels
1506+
1507+
>>> df.loc[['r1', 'r2'], ['c1']] = 70
1508+
>>> df
1509+
c0 c1 c2
1510+
r0 12 2 3
1511+
r1 0 70 1
1512+
r2 10 70 30
1513+
1514+
Set value for an entire row
1515+
1516+
>>> df.loc['r0'] = 70
1517+
>>> df
1518+
c0 c1 c2
1519+
r0 70 70 70
1520+
r1 0 70 1
1521+
r2 10 70 30
1522+
1523+
Set value for an entire column
1524+
1525+
>>> df.loc[:, 'c0'] = 30
1526+
>>> df
1527+
c0 c1 c2
1528+
r0 30 70 70
1529+
r1 30 70 1
1530+
r2 30 70 30
1531+
1532+
Set value for rows matching callable condition
1533+
1534+
>>> df.loc[df['c2'] < 10] = 0
1535+
>>> df
1536+
c0 c1 c2
1537+
r0 30 70 70
1538+
r1 0 0 0
1539+
r2 30 70 30
1540+
15041541
Another example using integers for the index
15051542
15061543
>>> df = pd.DataFrame([[12, 2, 3], [0, 4, 1], [10, 20, 30]],

0 commit comments

Comments
 (0)