MCPcopy
hub / github.com/pandas-dev/pandas / items

Method items

pandas/core/frame.py:1484–1536  ·  view source on GitHub ↗

r""" Iterate over (column name, Series) pairs. Iterates over the DataFrame columns, returning a tuple with the column name and the content as a Series. Yields ------ label : object The column names for the DataFrame being iterated over.

(self)

Source from the content-addressed store, hash-verified

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

Callers 15

memory_usageMethod · 0.95
duplicatedMethod · 0.95
test_iteritemsMethod · 0.95
test_itemsMethod · 0.95
test_itemsFunction · 0.95
from_recordsMethod · 0.45
assignMethod · 0.45

Calls 1

_ixsMethod · 0.95