You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/source/indexing.rst
+14-13
Original file line number
Diff line number
Diff line change
@@ -743,9 +743,9 @@ Selecting Random Samples
743
743
744
744
A random selection of rows or columns from a Series, DataFrame, or Panel with the :meth:`~DataFrame.sample` method. The method will sample rows by default, and accepts a specific number of rows/columns to return, or a fraction of rows.
745
745
746
-
.. ipython:: python
746
+
.. ipython:: python
747
747
748
-
s = pd.Series([0,1,2,3,4,5])
748
+
s = pd.Series([0,1, 2, 3, 4, 5])
749
749
750
750
# When no arguments are passed, returns 1 row.
751
751
s.sample()
@@ -759,9 +759,9 @@ A random selection of rows or columns from a Series, DataFrame, or Panel with th
759
759
By default, ``sample`` will return each row at most once, but one can also sample with replacement
760
760
using the ``replace`` option:
761
761
762
-
.. ipython:: python
762
+
.. ipython:: python
763
763
764
-
s = pd.Series([0,1,2,3,4,5])
764
+
s = pd.Series([0,1, 2, 3, 4, 5])
765
765
766
766
# Without replacement (default):
767
767
s.sample(n=6, replace=False)
@@ -774,9 +774,9 @@ By default, each row has an equal probability of being selected, but if you want
774
774
to have different probabilities, you can pass the ``sample`` function sampling weights as
775
775
``weights``. These weights can be a list, a NumPy array, or a Series, but they must be of the same length as the object you are sampling. Missing values will be treated as a weight of zero, and inf values are not allowed. If weights do not sum to 1, they will be re-normalized by dividing all weights by the sum of the weights. For example:
776
776
777
-
.. ipython:: python
777
+
.. ipython:: python
778
778
779
-
s = pd.Series([0,1,2,3,4,5])
779
+
s = pd.Series([0,1, 2, 3, 4, 5])
780
780
example_weights = [0, 0, 0.2, 0.2, 0.2, 0.4]
781
781
s.sample(n=3, weights=example_weights)
782
782
@@ -788,23 +788,24 @@ When applied to a DataFrame, you can use a column of the DataFrame as sampling w
788
788
(provided you are sampling rows and not columns) by simply passing the name of the column
Finally, one can also set a seed for ``sample``'s random number generator using the ``random_state`` argument, which will accept either an integer (as a seed) or a NumPy RandomState object.
- ``drop_duplicates`` and ``duplicated`` now accept a ``keep`` keyword to target first, last, and all duplicates. The ``take_last`` keyword is deprecated, see :ref:`here <whatsnew_0170.deprecations>` (:issue:`6511`, :issue:`8505`)
454
455
455
-
.. ipython:: python
456
+
.. ipython:: python
456
457
457
458
s = pd.Series(['A', 'B', 'C', 'A', 'B', 'D'])
458
459
s.drop_duplicates()
@@ -630,13 +631,13 @@ Of course you can coerce this as well.
0 commit comments