| [ Web Proxy ] |
| Viewing: https://dataframes.bigquery.dev/reference/api/bigframes.pandas.DataFrame.value_counts.html | [Back] [Original] |
Section Navigation
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_wings
falcon 2 2
dog 4 0
cat 4 0
ant 6 0
octopus 7 <NA>
[5 rows x 2 columns]
value_counts sorts the result by counts in a descending order by default:
>>> df.value_counts()
num_legs num_wings
4 0 2
2 2 1
6 0 1
Name: count, dtype: Int64
You can normalize the counts to return relative frequencies by setting normalize=True:
>>> df.value_counts(normalize=True)
num_legs num_wings
4 0 0.5
2 2 0.25
6 0 0.25
Name: 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_wings
2 2 1
6 0 1
4 0 2
Name: count, dtype: Int64
You can include the counts of the rows with NA values by setting dropna=False:
>>> df.value_counts(dropna=False)
num_legs num_wings
4 0 2
2 2 1
6 0 1
7 <NA> 1
Name: count, dtype: Int64
subset (label or list of labels, 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) Dont include counts of rows that contain NA values.
Series containing counts of unique rows in the DataFrame
Copyright 2019, Google.
Created using Sphinx 8.1.3.
Built with the PyData Sphinx Theme 0.19.0.
| Web Proxy Viewer | New URL | Original Page |