Skip to content

DOC: update the Series.reset_index DocString #20107

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 12 commits into from
Mar 15, 2018
60 changes: 49 additions & 11 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,24 +1002,34 @@ def _set_value(self, label, value, takeable=False):

def reset_index(self, level=None, drop=False, name=None, inplace=False):
"""
Analogous to the :meth:`pandas.DataFrame.reset_index` function, see
docstring there.
Reset the index of the Serie.
Copy link
Member

Choose a reason for hiding this comment

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

General comment: Serie -> Series (the singular of Series is still Series :))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved tnx!

Copy link
Member

Choose a reason for hiding this comment

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

Did you already push? Because this one is not yet fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I missed it!


For an Index, the index name will be used (if set),
otherwise a default index or `level_0` (if `index` is already taken)
Copy link
Contributor

Choose a reason for hiding this comment

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

the default IS 'index', can you make this a bit more clear

will be used.
For a MultiIndex, return a new Series with labeling
Copy link
Contributor

Choose a reason for hiding this comment

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

you will get a multi-column DataFrame, with each level being turned into a column, here the levels will be named level_n if the name is None.

information in the columns under the index names, defaulting to
`level_0`, `level_1`, etc. if any are None.

Parameters
----------
level : int, str, tuple, or list, default None
level : int, str, tuple, or list, default `None`
Only remove the given levels from the index. Removes all levels by
default
drop : boolean, default False
Do not try to insert index into dataframe columns
name : object, default None
The name of the column corresponding to the Series values
inplace : boolean, default False
Modify the Series in place (do not create a new object)
default.
drop : `bool`, default `False`
Do not try to insert index into dataframe columns.
name : `object`, default `None`
The name of the column corresponding to the Series values.
inplace : `bool`, default `False`
Copy link
Member

Choose a reason for hiding this comment

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

Can you also remove the backticks here? In general: no backticks in the type descriptions

Modify the Series in place (do not create a new object).

Returns
----------
resetted : DataFrame, or Series if drop == True
reset : `DataFrame`, or Series if `drop == True`
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't recall whether we are single ticking Series, DataFrame in doc-strings. @datapythonista @jorisvandenbossche

Copy link
Member

Choose a reason for hiding this comment

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

decision was to not use ticks in this case

Copy link
Contributor

Choose a reason for hiding this comment

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

ok @ludusrusso can you update


See Also
--------
pandas.DataFrame.reset_index: Analogous function for DataFrame
Copy link
Contributor

Choose a reason for hiding this comment

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

link to pandas.Series.set_index as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Series does not have a method set_index(), did you mean DataFrame.set_index()?

s.set_index()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ludus/develop/pandas-meetup/pandas/pandas/core/generic.py", line 4046, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'set_index'


Examples
--------
Expand All @@ -1032,6 +1042,34 @@ def reset_index(self, level=None, drop=False, name=None, inplace=False):
2 c 3
3 d 4

>>> s = pd.Series([1, 2, 3, 4], index=pd.Index(['a', 'b', 'c', 'd'],
... name = 'idx'))
>>> s.reset_index(drop=True)
0 1
1 2
2 3
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add an example with name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, for name and for inplace

3 4
dtype: int64

>>> s = pd.Series([1, 2, 3, 4], index=pd.Index(['a', 'b', 'c', 'd'],
... name = 'idx'))
>>> s.reset_index(name = 'new_idx')
Copy link
Contributor

Choose a reason for hiding this comment

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

no spaces around the equals

idx new_idx
0 a 1
1 b 2
2 c 3
3 d 4

>>> s = pd.Series([1, 2, 3, 4], index=pd.Index(['a', 'b', 'c', 'd'],
Copy link
Member

Choose a reason for hiding this comment

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

you don't need to re-define the series, you can reuse from the previous code block

Copy link
Member

Choose a reason for hiding this comment

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

Can you also put some explanation sentence between the examples?

... name = 'idx'))
>>> s.reset_index(inplace=True, drop=True)
>>> s
0 1
1 2
2 3
3 4
dtype: int64

>>> arrays = [np.array(['bar', 'bar', 'baz', 'baz', 'foo',
... 'foo', 'qux', 'qux']),
... np.array(['one', 'two', 'one', 'two', 'one', 'two',
Copy link
Member

Choose a reason for hiding this comment

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

If I'm not wrong, just 4 rows should be enough to illustrate the example. That would make it more compact, and easier to understand for the user.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, that was an existing example!

Expand Down