value_counts(self, subset: 'Sequence[Hashable] | None' = None, normalize: 'bool' = False, sort: 'bool' = True, ascending: 'bool' = False, dropna: 'bool' = True) -> 'DataFrame | Series'
If the groupby as_index is True then the returned Series will have a MultiIndex with one level per input column.
If the groupby as_index is False then the returned DataFrame will have an additional column with the value_counts. The column is labelled 'count' or 'proportion', depending on the normalize
parameter.
By default, rows that contain any NA values are omitted from the result.
By default, the result will be in descending order so that the first element of each group is the most frequently-occurring row.
Columns to use when counting unique combinations.
Return proportions rather than frequencies.
Sort by frequencies.
Sort in ascending order.
Don’t include counts of rows that contain NA values.
Series if the groupby as_index is True, otherwise DataFrame.
Return a Series or DataFrame containing counts of unique rows.
DataFrame.value_counts
Equivalent method on DataFrame.
Series.value_counts
Equivalent method on Series.
SeriesGroupBy.value_counts
Equivalent method on SeriesGroupBy.
>>> df = pd.DataFrame({This example is valid syntax, but we were not able to check execution
... 'gender': ['male', 'male', 'female', 'male', 'female', 'male'],
... 'education': ['low', 'medium', 'high', 'low', 'high', 'low'],
... 'country': ['US', 'FR', 'US', 'FR', 'FR', 'FR']
... })
>>> df gender education country 0 male low US 1 male medium FR 2 female high US 3 male low FR 4 female high FR 5 male low FRThis example is valid syntax, but we were not able to check execution
>>> df.groupby('gender').value_counts() gender education country female high FR 1 US 1 male low FR 2 US 1 medium FR 1 dtype: int64This example is valid syntax, but we were not able to check execution
>>> df.groupby('gender').value_counts(ascending=True) gender education country female high FR 1 US 1 male low US 1 medium FR 1 low FR 2 dtype: int64This example is valid syntax, but we were not able to check execution
>>> df.groupby('gender').value_counts(normalize=True) gender education country female high FR 0.50 US 0.50 male low FR 0.50 US 0.25 medium FR 0.25 dtype: float64This example is valid syntax, but we were not able to check execution
>>> df.groupby('gender', as_index=False).value_counts() gender education country count 0 female high FR 1 1 female high US 1 2 male low FR 2 3 male low US 1 4 male medium FR 1This example is valid syntax, but we were not able to check execution
>>> df.groupby('gender', as_index=False).value_counts(normalize=True) gender education country proportion 0 female high FR 0.50 1 female high US 0.50 2 male low FR 0.50 3 male low US 0.25 4 male medium FR 0.25See :
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them