MCPcopy
hub / github.com/pandas-dev/pandas / value_counts

Method value_counts

pandas/core/frame.py:8560–8707  ·  view source on GitHub ↗

Return a Series containing the frequency of each distinct row in the DataFrame. Parameters ---------- subset : Hashable or a sequence of the previous, optional Columns to use when counting unique combinations. normalize : bool, default False

(
        self,
        subset: IndexLabel | None = None,
        normalize: bool = False,
        sort: bool = True,
        ascending: bool = False,
        dropna: bool = True,
    )

Source from the content-addressed store, hash-verified

8558 )
8559
8560 def value_counts(
8561 self,
8562 subset: IndexLabel | None = None,
8563 normalize: bool = False,
8564 sort: bool = True,
8565 ascending: bool = False,
8566 dropna: bool = True,
8567 ) -> Series:
8568 """
8569 Return a Series containing the frequency of each distinct row in the DataFrame.
8570
8571 Parameters
8572 ----------
8573 subset : Hashable or a sequence of the previous, optional
8574 Columns to use when counting unique combinations.
8575 normalize : bool, default False
8576 Return proportions rather than frequencies.
8577 sort : bool, default True
8578 Stable sort by frequencies when True. Preserve the order of the data
8579 when False.
8580
8581 .. versionchanged:: 3.0.0
8582
8583 Prior to 3.0.0, ``sort=False`` would sort by the columns values.
8584
8585 .. versionchanged:: 3.0.0
8586
8587 Prior to 3.0.0, the sort was unstable.
8588 ascending : bool, default False
8589 Sort in ascending order.
8590 dropna : bool, default True
8591 Do not include counts of rows that contain NA values.
8592
8593 Returns
8594 -------
8595 Series
8596 Series containing the frequency of each distinct row in the DataFrame.
8597
8598 See Also
8599 --------
8600 Series.value_counts: Equivalent method on Series.
8601
8602 Notes
8603 -----
8604 The returned Series will have a MultiIndex with one level per input
8605 column but an Index (non-multi) for a single label. By default, rows
8606 that contain any NA values are omitted from the result. By default,
8607 the resulting Series will be sorted by frequencies in descending order so that
8608 the first element is the most frequently-occurring row.
8609
8610 Examples
8611 --------
8612 >>> df = pd.DataFrame(
8613 ... {"num_legs": [2, 4, 4, 6], "num_wings": [2, 0, 0, 0]},
8614 ... index=["falcon", "dog", "cat", "ant"],
8615 ... )
8616 >>> df
8617 num_legs num_wings

Calls 6

groupbyMethod · 0.95
tolistMethod · 0.45
sizeMethod · 0.45
sort_valuesMethod · 0.45
sumMethod · 0.45
from_arraysMethod · 0.45