-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
DOC iteritems docstring update and examples #22658
Changes from 4 commits
0521552
5447a1f
8ccd554
fcc27e8
6dad21c
25da7f8
30026a4
5110b7c
76243b3
1b52a08
618318c
d8e5370
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 |
---|---|---|
|
@@ -728,11 +728,35 @@ 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. | ||
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. This description is a bit complex, and can give the impression that it's returning a dictionary. Something like "Iterates over the DataFrame columns, returning a tuple with the label and the content as a Series" or something similar would be clearer IMHO. |
||
|
||
Returns | ||
------- | ||
it : generator | ||
A generator that iterates over the columns of the frame. | ||
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. In the case of a genrator, instead of documenting that it returns a generator, we use the section
|
||
|
||
See also | ||
-------- | ||
iterrows : Iterate over DataFrame rows as (index, Series) pairs. | ||
itertuples : Iterate over DataFrame rows as namedtuples of the values. | ||
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.
Use |
||
|
||
Examples | ||
-------- | ||
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [0.1, 0.2]}, | ||
... index=['a', 'b']) | ||
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. Can you use something that looks more like a real world example? I think it makes things easier to read. See for example the example DataFrame in https://pandas-docs.github.io/pandas-docs-travis/generated/pandas.DataFrame.reset_index.html |
||
>>> df | ||
col1 col2 | ||
a 1 0.1 | ||
b 2 0.2 | ||
>>> for col in df.iteritems(): | ||
... print(col) | ||
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 think something like next would make things easier to understand:
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. Thanks for the edits! I rephrased the long description, changed the Yields section to cover label and content, prepended DataFrame. to the See Also examples, and reworked the Examples section to hopefully be more engaging. 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. did you push the changes? 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 got my git commands mixed up sheepishly, but it's pushed now |
||
... | ||
('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: | ||
|
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.
Technically this returns an
Iterator
(or more specifically aGenerator
). So I would leave this asIterator
or change this toGenerator
.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.
I thought to make the change to 'Iterate over DataFrame ... as (..., Series) pairs to stay within the style of the iterrows and itertuples functions, but I can revert back to 'Iterator over (column name, Series) pairs.