Skip to content

Commit a851401

Browse files
Ecboxerjorisvandenbossche
authored andcommitted
DOC iteritems docstring update and examples (pandas-dev#22658)
1 parent 7343fd3 commit a851401

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

pandas/core/frame.py

+40-4
Original file line numberDiff line numberDiff line change
@@ -779,14 +779,50 @@ def style(self):
779779
return Styler(self)
780780

781781
def iteritems(self):
782-
"""
782+
r"""
783783
Iterator over (column name, Series) pairs.
784784
785-
See also
785+
Iterates over the DataFrame columns, returning a tuple with the column name
786+
and the content as a Series.
787+
788+
Yields
789+
------
790+
label : object
791+
The column names for the DataFrame being iterated over.
792+
content : Series
793+
The column entries belonging to each label, as a Series.
794+
795+
See Also
786796
--------
787-
iterrows : Iterate over DataFrame rows as (index, Series) pairs.
788-
itertuples : Iterate over DataFrame rows as namedtuples of the values.
797+
DataFrame.iterrows : Iterate over DataFrame rows as (index, Series) pairs.
798+
DataFrame.itertuples : Iterate over DataFrame rows as namedtuples of the values.
789799
800+
Examples
801+
--------
802+
>>> df = pd.DataFrame({'species': ['bear', 'bear', 'marsupial'],
803+
... 'population': [1864, 22000, 80000]},
804+
... index=['panda', 'polar', 'koala'])
805+
>>> df
806+
species population
807+
panda bear 1864
808+
polar bear 22000
809+
koala marsupial 80000
810+
>>> for label, content in df.iteritems():
811+
... print('label:', label)
812+
... print('content:', content, sep='\n')
813+
...
814+
label: species
815+
content:
816+
panda bear
817+
polar bear
818+
koala marsupial
819+
Name: species, dtype: object
820+
label: population
821+
content:
822+
panda 1864
823+
polar 22000
824+
koala 80000
825+
Name: population, dtype: int64
790826
"""
791827
if self.columns.is_unique and hasattr(self, '_item_cache'):
792828
for k in self.columns:

0 commit comments

Comments
 (0)