@@ -3525,46 +3525,45 @@ def filter(self, items=None, like=None, regex=None, axis=None):
3525
3525
Parameters
3526
3526
----------
3527
3527
items : list-like
3528
- List of info axis to restrict to (must not all be present)
3528
+ List of info axis to restrict to (must not all be present).
3529
3529
like : string
3530
- Keep info axis where "arg in col == True"
3530
+ Keep info axis where "arg in col == True".
3531
3531
regex : string (regular expression)
3532
- Keep info axis with re.search(regex, col) == True
3532
+ Keep info axis with re.search(regex, col) == True.
3533
3533
axis : int or string axis name
3534
3534
The axis to filter on. By default this is the info axis,
3535
- 'index' for Series, 'columns' for DataFrame
3535
+ 'index' for Series, 'columns' for DataFrame.
3536
3536
3537
3537
Returns
3538
3538
-------
3539
3539
same type as input object
3540
3540
3541
3541
Examples
3542
3542
--------
3543
- >>> df
3544
- one two three
3545
- mouse 1 2 3
3546
- rabbit 4 5 6
3543
+ >>> df = pd.DataFrame(np.array(([1,2,3],[4,5,6])),
3544
+ ... index=['mouse', 'rabbit'],
3545
+ ... columns=['one', 'two', 'three'])
3547
3546
3548
3547
>>> # select columns by name
3549
3548
>>> df.filter(items=['one', 'three'])
3550
- one three
3549
+ one three
3551
3550
mouse 1 3
3552
3551
rabbit 4 6
3553
3552
3554
3553
>>> # select columns by regular expression
3555
3554
>>> df.filter(regex='e$', axis=1)
3556
- one three
3555
+ one three
3557
3556
mouse 1 3
3558
3557
rabbit 4 6
3559
3558
3560
3559
>>> # select rows containing 'bbi'
3561
3560
>>> df.filter(like='bbi', axis=0)
3562
- one two three
3561
+ one two three
3563
3562
rabbit 4 5 6
3564
3563
3565
3564
See Also
3566
3565
--------
3567
- pandas.DataFrame.loc
3566
+ pandas.DataFrame.loc : Purely label-location based indexer for selection by label.
3568
3567
3569
3568
Notes
3570
3569
-----
@@ -3794,6 +3793,19 @@ def sample(self, n=None, frac=None, replace=False, weights=None,
3794
3793
40 0.823173 -0.078816 1.009536 1.015108
3795
3794
15 1.421154 -0.055301 -1.922594 -0.019696
3796
3795
6 -0.148339 0.832938 1.787600 -1.383767
3796
+
3797
+ You can use `random state` for reproducibility:
3798
+
3799
+ >>> df.sample(random_state=1)
3800
+ A B C D
3801
+ 37 -2.027662 0.103611 0.237496 -0.165867
3802
+ 43 -0.259323 -0.583426 1.516140 -0.479118
3803
+ 12 -1.686325 -0.579510 0.985195 -0.460286
3804
+ 8 1.167946 0.429082 1.215742 -1.636041
3805
+ 9 1.197475 -0.864188 1.554031 -1.505264
3806
+
3807
+
3808
+
3797
3809
"""
3798
3810
3799
3811
if axis is None :
0 commit comments