count distinct values in pandas column code example

Example 1: pandas groupby column count distinct values

# Pandas group by a column looking at the count unique/count distinct values of another column

df.groupby('param')['group'].nunique()

Example 2: how to get distinct value in a column dataframe in python

df.column.unique()

Example 3: how to count unique values in a column dataframe in python

dataframe.column.nunique()

Example 4: pandas count unique values in column

df.nunique()

Example 5: Returns a new DataFrame containing the distinct rows in this DataFrame

# Returns a new DataFrame containing the distinct rows in this DataFrame

df.ditinct().count()
# 2