-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
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
Changes from 1 commit
92ab782
0aa8a10
a8b96e6
baaaa07
45d7841
d062f8d
b0da5c3
15735ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "one wants" (but "you want" probably sounds better) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if people have thoughts here. I guess There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Iterable of tuples containing the |
||
|
||
See Also | ||
-------- | ||
Series.apply : Invoke function on values of Series. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) | ||
|
||
|
There was a problem hiding this comment.
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"?