bigframes.pandas.DataFrame.value_counts#
- DataFrame.value_counts(subset:Hashable|Sequence[Hashable]=None,normalize:bool=False,sort:bool=True,ascending:bool=False,dropna:bool=True)[source]#
Return a Series containing counts of unique rows in the DataFrame.
Examples:
>>>df=bpd.DataFrame({'num_legs':[2,4,4,6,7],...'num_wings':[2,0,0,0,pd.NA]},...index=['falcon','dog','cat','ant','octopus'],...dtype='Int64')>>>df num_legs num_wingsfalcon 2 2dog 4 0cat 4 0ant 6 0octopus 7 <NA>[5 rows x 2 columns]
value_countssorts the result by counts in a descending order by default:>>>df.value_counts()num_legs num_wings4 0 22 2 16 0 1Name: count, dtype: Int64
You can normalize the counts to return relative frequencies by setting
normalize=True:>>>df.value_counts(normalize=True)num_legs num_wings4 0 0.52 2 0.256 0 0.25Name: proportion, dtype: Float64
You can get the rows in the ascending order of the counts by setting
ascending=True:>>>df.value_counts(ascending=True)num_legs num_wings2 2 16 0 14 0 2Name: count, dtype: Int64
You can include the counts of the rows with
NAvalues by settingdropna=False:>>>df.value_counts(dropna=False)num_legs num_wings4 0 22 2 16 0 17 <NA> 1Name: count, dtype: Int64
- Parameters:
subset (label orlist oflabels,optional) – Columns to use when counting unique combinations.
normalize (bool,default False) – Return proportions rather than frequencies.
sort (bool,default True) – Sort by frequencies.
ascending (bool,default False) – Sort in ascending order.
dropna (bool,default True) – Don’t include counts of rows that contain NA values.
- Returns:
Series containing counts of unique rows in the DataFrame
- Return type: