Value Counts & Unique
Analyze the distribution of values in your data with value_counts() and related methods.
Basic Value Counts
Count occurrences of each unique value:
Loading Pandas Playground...
Normalized Counts (Percentages)
Get proportions instead of counts:
Loading Pandas Playground...
Sorting Options
Control the order of results:
Loading Pandas Playground...
Binning with Value Counts
Count values in ranges:
Loading Pandas Playground...
Unique Values
Get distinct values:
Loading Pandas Playground...
Value Counts Across Multiple Columns
Count combinations:
Loading Pandas Playground...
Including Missing Values
Count NaN as a category:
Loading Pandas Playground...
Exercise: Count Categories
Loading Exercise...
Exercise: Count Unique
Loading Exercise...
Key Points
value_counts()counts unique valuesnormalize=Truefor percentagessort_index()to sort by valuesunique()returns array of unique valuesnunique()counts unique valuesdropna=Falseincludes NaN in counts- Can count combinations of multiple columns

