From 837c26343cb8c4a0a3ddd3c5eba8d400dd191516 Mon Sep 17 00:00:00 2001 From: ottiP Date: Sat, 10 Mar 2018 12:43:42 +0100 Subject: [PATCH 1/2] DOC: Improved the docstring of pandas.Series.sample --- pandas/core/generic.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a893b2ba1a189..1fac34c71699a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3718,7 +3718,9 @@ def tail(self, n=5): def sample(self, n=None, frac=None, replace=False, weights=None, random_state=None, axis=None): """ - Returns a random sample of items from an axis of object. + Return a random sample of items from an axis of object. + + You can use `random_state` for reproducibility. Parameters ---------- @@ -3753,9 +3755,15 @@ def sample(self, n=None, frac=None, replace=False, weights=None, ------- A new object of same type as caller. - Examples + See Also -------- + Series.sample : Returns a random sample of items + from an axis of object. + DataFrame.sample : Returns a random sample of items + from an axis of object. + Examples + -------- Generate an example ``Series`` and ``DataFrame``: >>> s = pd.Series(np.random.randn(50)) @@ -3794,6 +3802,16 @@ def sample(self, n=None, frac=None, replace=False, weights=None, 40 0.823173 -0.078816 1.009536 1.015108 15 1.421154 -0.055301 -1.922594 -0.019696 6 -0.148339 0.832938 1.787600 -1.383767 + + You can use `random state` for reproducibility: + + >>> df.sample(random_state=1) + A B C D + 37 -2.027662 0.103611 0.237496 -0.165867 + 43 -0.259323 -0.583426 1.516140 -0.479118 + 12 -1.686325 -0.579510 0.985195 -0.460286 + 8 1.167946 0.429082 1.215742 -1.636041 + 9 1.197475 -0.864188 1.554031 -1.505264 """ if axis is None: From 170eabf4dea8b0cc0b56eb4b24d388b03a6390a4 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Thu, 15 Mar 2018 15:11:13 +0100 Subject: [PATCH 2/2] remove see also (they are pointing to themselves) --- pandas/core/generic.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 1fac34c71699a..9186cb33e5b7a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3755,13 +3755,6 @@ def sample(self, n=None, frac=None, replace=False, weights=None, ------- A new object of same type as caller. - See Also - -------- - Series.sample : Returns a random sample of items - from an axis of object. - DataFrame.sample : Returns a random sample of items - from an axis of object. - Examples -------- Generate an example ``Series`` and ``DataFrame``: