@@ -1472,8 +1472,57 @@ def style(self) -> Styler:
1472
1472
Name: population, dtype: int64
1473
1473
"""
1474
1474
1475
- @Appender (_shared_docs ["items" ])
1476
1475
def items (self ) -> Iterable [tuple [Hashable , Series ]]:
1476
+ r"""
1477
+ Iterate over (column name, Series) pairs.
1478
+
1479
+ Iterates over the DataFrame columns, returning a tuple with
1480
+ the column name and the content as a Series.
1481
+
1482
+ Yields
1483
+ ------
1484
+ label : object
1485
+ The column names for the DataFrame being iterated over.
1486
+ content : Series
1487
+ The column entries belonging to each label, as a Series.
1488
+
1489
+ See Also
1490
+ --------
1491
+ DataFrame.iterrows : Iterate over DataFrame rows as
1492
+ (index, Series) pairs.
1493
+ DataFrame.itertuples : Iterate over DataFrame rows as namedtuples
1494
+ of the values.
1495
+
1496
+ Examples
1497
+ --------
1498
+ >>> df = pd.DataFrame(
1499
+ ... {
1500
+ ... "species": ["bear", "bear", "marsupial"],
1501
+ ... "population": [1864, 22000, 80000],
1502
+ ... },
1503
+ ... index=["panda", "polar", "koala"],
1504
+ ... )
1505
+ >>> df
1506
+ species population
1507
+ panda bear 1864
1508
+ polar bear 22000
1509
+ koala marsupial 80000
1510
+ >>> for label, content in df.items():
1511
+ ... print(f"label: {label}")
1512
+ ... print(f"content: {content}", sep="\n")
1513
+ label: species
1514
+ content:
1515
+ panda bear
1516
+ polar bear
1517
+ koala marsupial
1518
+ Name: species, dtype: object
1519
+ label: population
1520
+ content:
1521
+ panda 1864
1522
+ polar 22000
1523
+ koala 80000
1524
+ Name: population, dtype: int64
1525
+ """
1477
1526
for i , k in enumerate (self .columns ):
1478
1527
yield k , self ._ixs (i , axis = 1 )
1479
1528
0 commit comments