Skip to content

Commit 7b45468

Browse files
jordan-d-murphypmhatre1
authored andcommitted
Doc: resolve GL08 for pandas.core.groupby.SeriesGroupBy.value_counts (pandas-dev#57609)
1 parent 6627a62 commit 7b45468

File tree

2 files changed

+82
-4
lines changed

2 files changed

+82
-4
lines changed

ci/code_checks.sh

-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
178178
pandas.Timestamp.tzinfo\
179179
pandas.Timestamp.value\
180180
pandas.Timestamp.year\
181-
pandas.core.groupby.SeriesGroupBy.value_counts\
182181
pandas.tseries.offsets.BQuarterBegin.is_anchored\
183182
pandas.tseries.offsets.BQuarterBegin.is_on_offset\
184183
pandas.tseries.offsets.BQuarterBegin.n\

pandas/core/groupby/generic.py

+82-3
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,85 @@ def value_counts(
801801
bins=None,
802802
dropna: bool = True,
803803
) -> Series | DataFrame:
804+
"""
805+
Return a Series or DataFrame containing counts of unique rows.
806+
807+
.. versionadded:: 1.4.0
808+
809+
Parameters
810+
----------
811+
normalize : bool, default False
812+
Return proportions rather than frequencies.
813+
sort : bool, default True
814+
Sort by frequencies.
815+
ascending : bool, default False
816+
Sort in ascending order.
817+
bins : int or list of ints, optional
818+
Rather than count values, group them into half-open bins,
819+
a convenience for pd.cut, only works with numeric data.
820+
dropna : bool, default True
821+
Don't include counts of rows that contain NA values.
822+
823+
Returns
824+
-------
825+
Series or DataFrame
826+
Series if the groupby ``as_index`` is True, otherwise DataFrame.
827+
828+
See Also
829+
--------
830+
Series.value_counts: Equivalent method on Series.
831+
DataFrame.value_counts: Equivalent method on DataFrame.
832+
DataFrameGroupBy.value_counts: Equivalent method on DataFrameGroupBy.
833+
834+
Notes
835+
-----
836+
- If the groupby ``as_index`` is True then the returned Series will have a
837+
MultiIndex with one level per input column.
838+
- If the groupby ``as_index`` is False then the returned DataFrame will have an
839+
additional column with the value_counts. The column is labelled 'count' or
840+
'proportion', depending on the ``normalize`` parameter.
841+
842+
By default, rows that contain any NA values are omitted from
843+
the result.
844+
845+
By default, the result will be in descending order so that the
846+
first element of each group is the most frequently-occurring row.
847+
848+
Examples
849+
--------
850+
>>> s = pd.Series(
851+
... [1, 1, 2, 3, 2, 3, 3, 1, 1, 3, 3, 3],
852+
... index=["A", "A", "A", "A", "A", "A", "B", "B", "B", "B", "B", "B"],
853+
... )
854+
>>> s
855+
A 1
856+
A 1
857+
A 2
858+
A 3
859+
A 2
860+
A 3
861+
B 3
862+
B 1
863+
B 1
864+
B 3
865+
B 3
866+
B 3
867+
dtype: int64
868+
>>> g1 = s.groupby(s.index)
869+
>>> g1.value_counts(bins=2)
870+
A (0.997, 2.0] 4
871+
(2.0, 3.0] 2
872+
B (2.0, 3.0] 4
873+
(0.997, 2.0] 2
874+
Name: count, dtype: int64
875+
>>> g1.value_counts(normalize=True)
876+
A 1 0.333333
877+
2 0.333333
878+
3 0.333333
879+
B 3 0.666667
880+
1 0.333333
881+
Name: proportion, dtype: float64
882+
"""
804883
name = "proportion" if normalize else "count"
805884

806885
if bins is None:
@@ -2303,7 +2382,7 @@ def value_counts(
23032382
Returns
23042383
-------
23052384
Series or DataFrame
2306-
Series if the groupby as_index is True, otherwise DataFrame.
2385+
Series if the groupby ``as_index`` is True, otherwise DataFrame.
23072386
23082387
See Also
23092388
--------
@@ -2313,9 +2392,9 @@ def value_counts(
23132392
23142393
Notes
23152394
-----
2316-
- If the groupby as_index is True then the returned Series will have a
2395+
- If the groupby ``as_index`` is True then the returned Series will have a
23172396
MultiIndex with one level per input column.
2318-
- If the groupby as_index is False then the returned DataFrame will have an
2397+
- If the groupby ``as_index`` is False then the returned DataFrame will have an
23192398
additional column with the value_counts. The column is labelled 'count' or
23202399
'proportion', depending on the ``normalize`` parameter.
23212400

0 commit comments

Comments
 (0)