Skip to content

DOC: Improve the docsting of Series.iteritems #24879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 19, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about "iterable" instead of "zip"?

one want to create new series from the values of an old one. Be aware
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"one wants" (but "you want" probably sounds better)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about creating a new series using itertuples. I'd rather say something about lazily iterating over the index, value pairs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure to perfectly get what you mean. I tried to add an example where vectorization is not possible (as far as I know maybe I am wrong)

that this might not the fastest way of creating new series.

Returns
-------
zip
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if people have thoughts here. I guess zip is technically a type... But I think Iterable is probably better-known.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I think iterable would be more user-friendly.

Iterable tuples (index, value) of the Series.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Iterable of tuples containing the (index, value) pairs from a Series.


See Also
--------
Series.apply : Invoke function on values of Series.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if Series.apply and Series.map are too related to this method. I would instead reference Series.items

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I am mistaken, it seems to me that Series.iteritems and Series.items are the same method. The docstring of items and iteritems will be the same I don't think that this is a good idea.

I will mention it in the description instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that apply and map aren't closely enough related to include here - can you remove?

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))

Expand Down