-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: Extend docstring pandas core index to_frame method #20036
Changes from 5 commits
5387d95
b99e4a2
90eb4af
2e26d8a
f3e1019
535eba9
e6cbbbe
b32b416
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 |
---|---|---|
|
@@ -1110,19 +1110,37 @@ def to_series(self, index=None, name=None): | |
return Series(self._to_embed(), index=index, name=name) | ||
|
||
def to_frame(self, index=True): | ||
""" | ||
Create a DataFrame with a column containing the Index. | ||
"""Create a DataFrame with a column containing the Index. | ||
|
||
.. versionadded:: 0.21.0 | ||
|
||
Parameters | ||
---------- | ||
index : boolean, default True | ||
Set the index of the returned DataFrame as the original Index. | ||
index : boolean | ||
Set the index of the returned DataFrame as the original Index | ||
(default True). | ||
|
||
Returns | ||
------- | ||
DataFrame : a DataFrame containing the original Index data. | ||
DataFrame | ||
DataFrame containing the original Index data. | ||
|
||
Examples | ||
-------- | ||
>>> idx = pd.Index(['Ant', 'Bear', 'Cow']) | ||
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. Minor thing, but it'd probably look a bit nicer if you create the index with 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. Well, I do think it is interesting when creating a new index:
but when using the same as index and column, it does not get 'nicer':
|
||
>>> idx.to_frame() | ||
0 | ||
Ant Ant | ||
Bear Bear | ||
Cow Cow | ||
|
||
By default, the original Index is reused. To enforce a new Index: | ||
|
||
>>> idx.to_frame(index=False) | ||
0 | ||
0 Ant | ||
1 Bear | ||
2 Cow | ||
""" | ||
|
||
from pandas import DataFrame | ||
|
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.
@datapythonista @jorisvandenbossche defaults on the same line, yes?
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.
Yes, the documentation still says to use it the numpy way (in brackets after the description), but in pandas-dev the consensus seems to be keeping the pandas way, which was already right in this case. Will update the documentation asap and send an email with the last minute changes to the organizers
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.
Yes, the docstring guide has been updated, but apparently only in the source: https://github.com/python-sprints/python-sprints.github.io/blob/master/pandas/guide/source/pandas_docstring.rst and not yet in the online version