Skip to content

Commit 4838155

Browse files
committed
DOC: added examples to reset_index
1 parent 2a51e2b commit 4838155

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

pandas/core/series.py

+30
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,36 @@ def reset_index(self, level=None, drop=False, name=None, inplace=False):
948948
Returns
949949
----------
950950
resetted : DataFrame, or Series if drop == True
951+
952+
Examples
953+
--------
954+
>>> s = pd.Series([1, 2, 3, 4], index=pd.Index(['a', 'b', 'c', 'd'],
955+
... name = 'idx'))
956+
>>> s.reset_index()
957+
index 0
958+
0 0 1
959+
1 1 2
960+
2 2 3
961+
3 3 4
962+
>>> arrays = [np.array(['bar', 'bar', 'baz', 'baz', 'foo',
963+
... 'foo', 'qux', 'qux']),
964+
... np.array(['one', 'two', 'one', 'two', 'one', 'two',
965+
... 'one', 'two'])]
966+
>>> s2 = pd.Series(
967+
... np.random.randn(8),
968+
... index=pd.MultiIndex.from_arrays(arrays,
969+
... names=['a', 'b']))
970+
>>> s2.reset_index(level='a')
971+
a 0
972+
b
973+
one bar -0.286320
974+
two bar -0.587934
975+
one baz 0.710491
976+
two baz -1.429006
977+
one foo 0.790700
978+
two foo 0.824863
979+
one qux -0.718963
980+
two qux -0.055028
951981
"""
952982
inplace = validate_bool_kwarg(inplace, 'inplace')
953983
if drop:

0 commit comments

Comments
 (0)