From 92ab78257798f6ab0d58799cab9975a752672c36 Mon Sep 17 00:00:00 2001 From: Moi Date: Tue, 22 Jan 2019 22:54:26 +0100 Subject: [PATCH 1/6] DOC: Improve the docsting of Series.iteritems --- pandas/core/series.py | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/pandas/core/series.py b/pandas/core/series.py index 0c8e697c572e8..af89c07b96514 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1446,6 +1446,50 @@ def to_string(self, buf=None, na_rep='NaN', float_format=None, header=True, def iteritems(self): """ Lazily iterate over (index, value) tuples. + + This method returns a zip of tuples (index, value). This is useful When + one want to create new series from the values of an old one. Be aware + that this might not the fastest way of creating new series. + + Returns + ------- + zip + Iterable tuples (index, value) of the Series. + + See Also + -------- + Series.apply : Invoke function on values of Series. + Series.map : Map values of Series according to input correspondence. + DataFrame.iteritems : Equivalent to Series.iteritems for DataFrame. + + Examples + -------- + >>> s = pd.Series(['A', 'B', 'C']) + >>> for index, value in s.iteritems(): + ... print("Index : {}, Value : {}".format(index, value)) + Index : 0, Value : A + Index : 1, Value : B + Index : 2, Value : C + + **Creation of another Series** + + >>> s2 = pd.Series([]) + >>> for index, value in s.iteritems(): + ... s2[index] = value + value + >>> s2 + 0 AA + 1 BB + 2 CC + dtype: object + + **A faster way of creating the same Series** + + >>> s3 = s + s + >>> s3 + 0 AA + 1 BB + 2 CC + dtype: object """ return zip(iter(self.index), iter(self)) From 0aa8a1019305316d9d6e593add67ed91e2a28313 Mon Sep 17 00:00:00 2001 From: Moi Date: Thu, 24 Jan 2019 00:47:16 +0100 Subject: [PATCH 2/6] Corrections added --- pandas/core/series.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index af89c07b96514..f41aaec01fbdd 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1447,14 +1447,12 @@ def iteritems(self): """ Lazily iterate over (index, value) tuples. - This method returns a zip of tuples (index, value). This is useful When - one want to create new series from the values of an old one. Be aware - that this might not the fastest way of creating new series. + This method returns an iterable tuple (index, value). Returns ------- - zip - Iterable tuples (index, value) of the Series. + iterable + Iterable tuples (index, value) from a Series. See Also -------- @@ -1490,6 +1488,20 @@ def iteritems(self): 1 BB 2 CC dtype: object + + ** Another example ** + + >>> s4 = pd.Series([]) + >>> for index, value in s.iteritems(): + ... if index % 2 == 0: + ... s4[index] = value + '_even_index' + ... else: + ... s4[index] = value + '_odd_index' + >>> s4 + 0 A_even_index + 1 B_odd_index + 2 C_even_index + dtype: object """ return zip(iter(self.index), iter(self)) From baaaa073c0fb4d94d38c64a5bdbd2d94a7e82f2e Mon Sep 17 00:00:00 2001 From: Moi Date: Sun, 27 Jan 2019 00:34:55 +0100 Subject: [PATCH 3/6] Corrections --- pandas/core/series.py | 40 ++++------------------------------------ 1 file changed, 4 insertions(+), 36 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index f41aaec01fbdd..ffc809f62adb8 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1447,12 +1447,14 @@ def iteritems(self): """ Lazily iterate over (index, value) tuples. - This method returns an iterable tuple (index, value). + This method returns an iterable tuple (index, value). This is + convienient if you want to create a a Lazy iterator. Returns ------- iterable - Iterable tuples (index, value) from a Series. + Iterable of tuples containing the (index, value) pairs from a + Series. See Also -------- @@ -1468,40 +1470,6 @@ def iteritems(self): Index : 0, Value : A Index : 1, Value : B Index : 2, Value : C - - **Creation of another Series** - - >>> s2 = pd.Series([]) - >>> for index, value in s.iteritems(): - ... s2[index] = value + value - >>> s2 - 0 AA - 1 BB - 2 CC - dtype: object - - **A faster way of creating the same Series** - - >>> s3 = s + s - >>> s3 - 0 AA - 1 BB - 2 CC - dtype: object - - ** Another example ** - - >>> s4 = pd.Series([]) - >>> for index, value in s.iteritems(): - ... if index % 2 == 0: - ... s4[index] = value + '_even_index' - ... else: - ... s4[index] = value + '_odd_index' - >>> s4 - 0 A_even_index - 1 B_odd_index - 2 C_even_index - dtype: object """ return zip(iter(self.index), iter(self)) From 45d784111a95ca25f93035e01925e11c2f2d8820 Mon Sep 17 00:00:00 2001 From: Moi Date: Thu, 31 Jan 2019 23:04:09 +0100 Subject: [PATCH 4/6] Corrections added --- pandas/core/series.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index ffc809f62adb8..6f15991bf6c2e 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1448,7 +1448,8 @@ def iteritems(self): Lazily iterate over (index, value) tuples. This method returns an iterable tuple (index, value). This is - convienient if you want to create a a Lazy iterator. + convienient if you want to create a lazy iterator. Note that the methods + Series.items and Series.iteritems are the same methods. Returns ------- From d062f8dfb6d9da1d424dafc12ffd57173b01ffe5 Mon Sep 17 00:00:00 2001 From: Moi Date: Thu, 31 Jan 2019 23:10:54 +0100 Subject: [PATCH 5/6] corrections --- pandas/core/series.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 6f15991bf6c2e..7b38e1000a51c 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1448,8 +1448,8 @@ def iteritems(self): Lazily iterate over (index, value) tuples. This method returns an iterable tuple (index, value). This is - convienient if you want to create a lazy iterator. Note that the methods - Series.items and Series.iteritems are the same methods. + convienient if you want to create a lazy iterator. Note that the + methods Series.items and Series.iteritems are the same methods. Returns ------- From b0da5c3c829df70e0f0d1b3f26c6099fdf151a88 Mon Sep 17 00:00:00 2001 From: Moi Date: Sat, 16 Mar 2019 11:48:02 +0100 Subject: [PATCH 6/6] minor changes --- pandas/core/series.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 7b38e1000a51c..5bf6d055c8397 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1459,8 +1459,6 @@ def iteritems(self): See Also -------- - Series.apply : Invoke function on values of Series. - Series.map : Map values of Series according to input correspondence. DataFrame.iteritems : Equivalent to Series.iteritems for DataFrame. Examples