From 0521552662c81ec77e88fe4720e71b2e55d217fd Mon Sep 17 00:00:00 2001 From: Ecboxer Date: Sun, 2 Sep 2018 18:20:25 -0400 Subject: [PATCH 01/11] DOC Updated iteritems docstring to start with an infinitive and added a short example --- pandas/core/frame.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 74f760f382c76..821b0c4213833 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -726,13 +726,32 @@ def style(self): def iteritems(self): """ - Iterator over (column name, Series) pairs. + Iterate over DataFrame columns as (column name, Series) pairs. See also -------- iterrows : Iterate over DataFrame rows as (index, Series) pairs. itertuples : Iterate over DataFrame rows as namedtuples of the values. + Examples + -------- + + >>> df = pd.DataFrame({'col1': [1, 2], 'col2': [0.1, 0.2]}, + index=['a', 'b']) + >>> df + col1 col2 + a 1 0.1 + b 2 0.2 + >>> for col in df.iteritems(): + ... print(col) + ... + ('col1', a 1 + b 2 + Name: col1, dtype: int64) + ('col2', a 0.1 + b 0.2 + Name: col2, dtype: float64) + """ if self.columns.is_unique and hasattr(self, '_item_cache'): for k in self.columns: From 5447a1fb00441c78538d5ea06c4cd6772d446bc4 Mon Sep 17 00:00:00 2001 From: Ecboxer Date: Tue, 11 Sep 2018 09:14:50 -0400 Subject: [PATCH 02/11] Continuation lines start with ... and are aligned, reverted description to original --- pandas/core/frame.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 821b0c4213833..f9c1bb7a0773a 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -726,7 +726,7 @@ def style(self): def iteritems(self): """ - Iterate over DataFrame columns as (column name, Series) pairs. + Iterator over (column name, Series) pairs. See also -------- @@ -737,7 +737,7 @@ def iteritems(self): -------- >>> df = pd.DataFrame({'col1': [1, 2], 'col2': [0.1, 0.2]}, - index=['a', 'b']) + ... index=['a', 'b']) >>> df col1 col2 a 1 0.1 From 8ccd5541a3ffabd3e3456199d6f107949aa21fbe Mon Sep 17 00:00:00 2001 From: Ecboxer Date: Tue, 11 Sep 2018 21:13:27 -0400 Subject: [PATCH 03/11] Removed trailing space and added Returns/Yields section --- pandas/core/frame.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index f9c1bb7a0773a..cb2023ebc7324 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -728,6 +728,11 @@ def iteritems(self): """ Iterator over (column name, Series) pairs. + Returns + ------- + it : generator + A generator that iterates over the columns of the frame. + See also -------- iterrows : Iterate over DataFrame rows as (index, Series) pairs. @@ -735,7 +740,6 @@ def iteritems(self): Examples -------- - >>> df = pd.DataFrame({'col1': [1, 2], 'col2': [0.1, 0.2]}, ... index=['a', 'b']) >>> df @@ -751,7 +755,6 @@ def iteritems(self): ('col2', a 0.1 b 0.2 Name: col2, dtype: float64) - """ if self.columns.is_unique and hasattr(self, '_item_cache'): for k in self.columns: From fcc27e83db97b7d0677e665df7bb82caf49a73e6 Mon Sep 17 00:00:00 2001 From: Ecboxer Date: Tue, 11 Sep 2018 21:19:37 -0400 Subject: [PATCH 04/11] Added extended summary --- pandas/core/frame.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index cb2023ebc7324..3704ca2a7968e 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -728,6 +728,8 @@ def iteritems(self): """ Iterator over (column name, Series) pairs. + Iterates over columns as key, value dict-like pairs with columns name as keys and Series as values. + Returns ------- it : generator From 6dad21ce27cc5356c0215848ebdae8c48a9d8518 Mon Sep 17 00:00:00 2001 From: Ecboxer Date: Sun, 23 Sep 2018 10:15:04 -0400 Subject: [PATCH 05/11] Edits to long description, split Yields section into label and content, edits to See Also, and made a more engaging example --- pandas/core/frame.py | 57 ++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 3704ca2a7968e..dfb6bf3129ac3 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -728,35 +728,50 @@ def iteritems(self): """ Iterator over (column name, Series) pairs. - Iterates over columns as key, value dict-like pairs with columns name as keys and Series as values. + Iterates over the DataFrame columns, returning a tuple with the column name and the content as a Series. - Returns - ------- - it : generator - A generator that iterates over the columns of the frame. + Yields + ------ + label : object + The column names for the DataFrame being iterated over. + content : Series + The column entries belonging to each label, as a Series. - See also + See Also -------- - iterrows : Iterate over DataFrame rows as (index, Series) pairs. - itertuples : Iterate over DataFrame rows as namedtuples of the values. + DataFrame.iterrows : Iterate over DataFrame rows as (index, Series) pairs. + DataFrame.itertuples : Iterate over DataFrame rows as namedtuples of the values. Examples -------- - >>> df = pd.DataFrame({'col1': [1, 2], 'col2': [0.1, 0.2]}, - ... index=['a', 'b']) + >>> df = pd.DataFrame({'species': ['bear', 'bear', 'bear', 'bear', 'marsupial'], + ... 'pop': [300000, 200000, 1864, 22000, 80000]}, + ... index=['black', 'brown', 'panda', 'polar', 'koala']) >>> df - col1 col2 - a 1 0.1 - b 2 0.2 - >>> for col in df.iteritems(): - ... print(col) + species pop + black bear 300000 + brown bear 200000 + panda bear 1864 + polar bear 22000 + koala marsupial 80000 + >>> for label, content in df.iteritems(): + ... print('label:', label) + ... print('content:', content) ... - ('col1', a 1 - b 2 - Name: col1, dtype: int64) - ('col2', a 0.1 - b 0.2 - Name: col2, dtype: float64) + label: species + content: black bear + brown bear + panda bear + polar bear + koala marsupial + Name: species, dtype: object + label: pop + content: black 300000 + brown 200000 + panda 1864 + polar 22000 + koala 80000 + Name: pop, dtype: int64 """ if self.columns.is_unique and hasattr(self, '_item_cache'): for k in self.columns: From 30026a435026a846f51148a6020c71696d070282 Mon Sep 17 00:00:00 2001 From: Ecboxer Date: Tue, 25 Sep 2018 07:59:05 -0400 Subject: [PATCH 06/11] Changed pop to population and reformatted example --- pandas/core/frame.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 6025f0e85044d..55eb06b3f4ed0 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -798,10 +798,10 @@ def iteritems(self): Examples -------- >>> df = pd.DataFrame({'species': ['bear', 'bear', 'bear', 'bear', 'marsupial'], - ... 'pop': [300000, 200000, 1864, 22000, 80000]}, + ... 'population': [300000, 200000, 1864, 22000, 80000]}, ... index=['black', 'brown', 'panda', 'polar', 'koala']) >>> df - species pop + species population black bear 300000 brown bear 200000 panda bear 1864 @@ -809,17 +809,19 @@ def iteritems(self): koala marsupial 80000 >>> for label, content in df.iteritems(): ... print('label:', label) - ... print('content:', content) + ... print('content:', content, sep='\n', end='\n') ... label: species - content: black bear + content: + black bear brown bear panda bear polar bear koala marsupial Name: species, dtype: object label: pop - content: black 300000 + content: + black 300000 brown 200000 panda 1864 polar 22000 From 5110b7c004d0f761f13a519a276bbd3810013a97 Mon Sep 17 00:00:00 2001 From: Ecboxer Date: Tue, 25 Sep 2018 08:04:17 -0400 Subject: [PATCH 07/11] Changed pop to population in example output --- pandas/core/frame.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 55eb06b3f4ed0..8d7b04e189b3d 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -809,7 +809,7 @@ def iteritems(self): koala marsupial 80000 >>> for label, content in df.iteritems(): ... print('label:', label) - ... print('content:', content, sep='\n', end='\n') + ... print('content:', content, sep='\\n', end='\\n') ... label: species content: @@ -819,14 +819,14 @@ def iteritems(self): polar bear koala marsupial Name: species, dtype: object - label: pop + label: population content: black 300000 brown 200000 panda 1864 polar 22000 koala 80000 - Name: pop, dtype: int64 + Name: population, dtype: int64 """ if self.columns.is_unique and hasattr(self, '_item_cache'): for k in self.columns: From 76243b372a73dbf3869a5bde4d745be7f8906fb3 Mon Sep 17 00:00:00 2001 From: Ecboxer Date: Tue, 25 Sep 2018 09:14:49 -0400 Subject: [PATCH 08/11] Changed docstring to string literal and removed escape chars --- pandas/core/frame.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 8d7b04e189b3d..504db2d689d1f 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -778,7 +778,7 @@ def style(self): return Styler(self) def iteritems(self): - """ + r""" Iterator over (column name, Series) pairs. Iterates over the DataFrame columns, returning a tuple with the column name and the content as a Series. @@ -809,15 +809,15 @@ def iteritems(self): koala marsupial 80000 >>> for label, content in df.iteritems(): ... print('label:', label) - ... print('content:', content, sep='\\n', end='\\n') + ... print('content:', content, sep='\n', end='\n') ... label: species content: - black bear - brown bear - panda bear - polar bear - koala marsupial + black bear + brown bear + panda bear + polar bear + koala marsupial Name: species, dtype: object label: population content: From 1b52a08d69d32d49ecf92ab432a743ce72486f7e Mon Sep 17 00:00:00 2001 From: Ecboxer Date: Tue, 25 Sep 2018 09:17:19 -0400 Subject: [PATCH 09/11] Removed end="\n" --- pandas/core/frame.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 504db2d689d1f..e1d6720293b3c 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -809,7 +809,7 @@ def iteritems(self): koala marsupial 80000 >>> for label, content in df.iteritems(): ... print('label:', label) - ... print('content:', content, sep='\n', end='\n') + ... print('content:', content, sep='\n') ... label: species content: From 618318cdd159c50177a825dd951c8231d2700343 Mon Sep 17 00:00:00 2001 From: Ecboxer Date: Tue, 25 Sep 2018 09:53:16 -0400 Subject: [PATCH 10/11] Shortened example, fit long desc to char limit, changed Yields to description of one item it --- pandas/core/frame.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index e1d6720293b3c..3aa8e4f58cc89 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -781,14 +781,14 @@ def iteritems(self): r""" Iterator over (column name, Series) pairs. - Iterates over the DataFrame columns, returning a tuple with the column name and the content as a Series. + 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. - content : Series - The column entries belonging to each label, as a Series. + it : generator + A generator which iterates over the columns of the DataFrame and whose values + consist of the column name as a label and the column entries as a Series. See Also -------- @@ -797,13 +797,11 @@ def iteritems(self): Examples -------- - >>> df = pd.DataFrame({'species': ['bear', 'bear', 'bear', 'bear', 'marsupial'], - ... 'population': [300000, 200000, 1864, 22000, 80000]}, - ... index=['black', 'brown', 'panda', 'polar', 'koala']) + >>> df = pd.DataFrame({'species': ['bear', 'bear', 'marsupial'], + ... 'population': [1864, 22000, 80000]}, + ... index=['panda', 'polar', 'koala']) >>> df species population - black bear 300000 - brown bear 200000 panda bear 1864 polar bear 22000 koala marsupial 80000 @@ -813,16 +811,12 @@ def iteritems(self): ... label: species content: - black bear - brown bear panda bear polar bear koala marsupial Name: species, dtype: object label: population content: - black 300000 - brown 200000 panda 1864 polar 22000 koala 80000 From d8e5370e5660d15acfeaa153aed2a25c0fa31694 Mon Sep 17 00:00:00 2001 From: Ecboxer Date: Tue, 25 Sep 2018 10:12:40 -0400 Subject: [PATCH 11/11] Returned to two part Yields section, label and contents --- pandas/core/frame.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 3aa8e4f58cc89..288ff26b14bc4 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -786,9 +786,10 @@ def iteritems(self): Yields ------ - it : generator - A generator which iterates over the columns of the DataFrame and whose values - consist of the column name as a label and the column entries as a Series. + label : object + The column names for the DataFrame being iterated over. + content : Series + The column entries belonging to each label, as a Series. See Also --------