Count number of unique records in a Data Frame

Asked

Viewed 1,112 times

3

I have a base with a column custumer_id and I need to know the amount of unique records on the base.

quantidade_clientes = df[['customer_id']]
quantidade_clientes.count()

This way I count everyone, I want to know only who is unique.

1 answer

3


The pandas has the function .nunique(), which returns the amount of unique values in a Data Frame or a Series. In your case, just do:

df['customer_id'].nunique()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.