Skip to content

Commit 72eafde

Browse files
ottiPjorisvandenbossche
ottiP
authored andcommitted
DOC: Improved the docstring of pandas.Series.sample (#20109)
1 parent 87f5654 commit 72eafde

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

pandas/core/generic.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3951,7 +3951,9 @@ def tail(self, n=5):
39513951
def sample(self, n=None, frac=None, replace=False, weights=None,
39523952
random_state=None, axis=None):
39533953
"""
3954-
Returns a random sample of items from an axis of object.
3954+
Return a random sample of items from an axis of object.
3955+
3956+
You can use `random_state` for reproducibility.
39553957
39563958
Parameters
39573959
----------
@@ -3988,7 +3990,6 @@ def sample(self, n=None, frac=None, replace=False, weights=None,
39883990
39893991
Examples
39903992
--------
3991-
39923993
Generate an example ``Series`` and ``DataFrame``:
39933994
39943995
>>> s = pd.Series(np.random.randn(50))
@@ -4027,6 +4028,16 @@ def sample(self, n=None, frac=None, replace=False, weights=None,
40274028
40 0.823173 -0.078816 1.009536 1.015108
40284029
15 1.421154 -0.055301 -1.922594 -0.019696
40294030
6 -0.148339 0.832938 1.787600 -1.383767
4031+
4032+
You can use `random state` for reproducibility:
4033+
4034+
>>> df.sample(random_state=1)
4035+
A B C D
4036+
37 -2.027662 0.103611 0.237496 -0.165867
4037+
43 -0.259323 -0.583426 1.516140 -0.479118
4038+
12 -1.686325 -0.579510 0.985195 -0.460286
4039+
8 1.167946 0.429082 1.215742 -1.636041
4040+
9 1.197475 -0.864188 1.554031 -1.505264
40304041
"""
40314042

40324043
if axis is None:

0 commit comments

Comments
 (0)