From 2a51e2b1bd49eb8805e2cc20918b62a6f9bf37bd Mon Sep 17 00:00:00 2001 From: aernlund Date: Sat, 15 Jul 2017 16:16:53 -0500 Subject: [PATCH 1/3] DOC: added examples to reset_index --- pandas/core/frame.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 9920ddf854850..a9710a29291f4 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3020,6 +3020,37 @@ def reset_index(self, level=None, drop=False, inplace=False, col_level=0, Returns ------- resetted : DataFrame + + Examples + -------- + >>> df = pd.DataFrame({'a': [1, 2, 3, 4], 'b': [5, 6, 7, 8]}, + ... index=pd.Index(['a', 'b', 'c', 'd'], + ... name='idx')) + >>> df.reset_index() + idx a b + 0 a 1 5 + 1 b 2 6 + 2 c 3 7 + 3 d 4 8 + >>> arrays = [np.array(['bar', 'bar', 'baz', 'baz', 'foo', + ... 'foo', 'qux', 'qux']), + ... np.array(['one', 'two', 'one', 'two', 'one', 'two', + ... 'one', 'two'])] + >>> df2 = pd.DataFrame( + ... np.random.randn(8, 4), + ... index=pd.MultiIndex.from_arrays(arrays, + ... names=['a', 'b'])) + >>> df2.reset_index(level='a') + a 0 1 2 3 + b + one bar -1.099413 0.291838 0.598198 0.162181 + two bar -0.312184 -0.119904 0.250360 0.364378 + one baz 0.713596 -0.490636 0.074967 -0.297857 + two baz 0.998397 0.524499 -2.228976 0.901155 + one foo 0.923204 0.920695 1.264488 1.476921 + two foo -1.566922 0.783278 -0.073656 0.266027 + one qux -0.230470 0.109800 -1.383409 0.048421 + two qux -0.865993 -0.865984 0.705367 -0.170446 """ inplace = validate_bool_kwarg(inplace, 'inplace') if inplace: From 48381554f9268d5b1857aed9ea5cd1733eb7cece Mon Sep 17 00:00:00 2001 From: aernlund Date: Sat, 15 Jul 2017 16:55:54 -0500 Subject: [PATCH 2/3] DOC: added examples to reset_index --- pandas/core/series.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/pandas/core/series.py b/pandas/core/series.py index 98b548f8ab3b5..5bf23469d850f 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -948,6 +948,36 @@ def reset_index(self, level=None, drop=False, name=None, inplace=False): Returns ---------- resetted : DataFrame, or Series if drop == True + + Examples + -------- + >>> s = pd.Series([1, 2, 3, 4], index=pd.Index(['a', 'b', 'c', 'd'], + ... name = 'idx')) + >>> s.reset_index() + index 0 + 0 0 1 + 1 1 2 + 2 2 3 + 3 3 4 + >>> arrays = [np.array(['bar', 'bar', 'baz', 'baz', 'foo', + ... 'foo', 'qux', 'qux']), + ... np.array(['one', 'two', 'one', 'two', 'one', 'two', + ... 'one', 'two'])] + >>> s2 = pd.Series( + ... np.random.randn(8), + ... index=pd.MultiIndex.from_arrays(arrays, + ... names=['a', 'b'])) + >>> s2.reset_index(level='a') + a 0 + b + one bar -0.286320 + two bar -0.587934 + one baz 0.710491 + two baz -1.429006 + one foo 0.790700 + two foo 0.824863 + one qux -0.718963 + two qux -0.055028 """ inplace = validate_bool_kwarg(inplace, 'inplace') if drop: From 3c6a4b6e9fd1b1aa279c9a440caee328a33b5ffb Mon Sep 17 00:00:00 2001 From: aernlund Date: Sat, 15 Jul 2017 16:58:00 -0500 Subject: [PATCH 3/3] DOC: added examples to reset_index --- pandas/core/frame.py | 4 ++-- pandas/core/series.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index a9710a29291f4..5fa9755af4bf4 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3034,8 +3034,8 @@ def reset_index(self, level=None, drop=False, inplace=False, col_level=0, 3 d 4 8 >>> arrays = [np.array(['bar', 'bar', 'baz', 'baz', 'foo', ... 'foo', 'qux', 'qux']), - ... np.array(['one', 'two', 'one', 'two', 'one', 'two', - ... 'one', 'two'])] + ... np.array(['one', 'two', 'one', 'two', 'one', 'two', + ... 'one', 'two'])] >>> df2 = pd.DataFrame( ... np.random.randn(8, 4), ... index=pd.MultiIndex.from_arrays(arrays, diff --git a/pandas/core/series.py b/pandas/core/series.py index 5bf23469d850f..65692a519bdd8 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -961,8 +961,8 @@ def reset_index(self, level=None, drop=False, name=None, inplace=False): 3 3 4 >>> arrays = [np.array(['bar', 'bar', 'baz', 'baz', 'foo', ... 'foo', 'qux', 'qux']), - ... np.array(['one', 'two', 'one', 'two', 'one', 'two', - ... 'one', 'two'])] + ... np.array(['one', 'two', 'one', 'two', 'one', 'two', + ... 'one', 'two'])] >>> s2 = pd.Series( ... np.random.randn(8), ... index=pd.MultiIndex.from_arrays(arrays,