AcoffeePls
AcoffeePls

Reputation: 11

Counting unique values or lables in a dataset

Im having a problem counting the diffrent directors and how many films they each released in my data frame, the output i want is director x, 22 films director y, 13 films, my code goes as follows

directors=movies.iloc[:,14]
directors
#this is me selecting out the director column
directors.nunique()
#this me trying to find the unique values, however it only prints
2101

Upvotes: 0

Views: 219

Answers (2)

polaris
polaris

Reputation: 11

nuique() returns the number of unique values within a given array. The value 2101 is being returned because there are 2101 values in the selection you have.

If you're trying to find a number of films for each unique directory I would do:

for director in movies.iloc[:,14].unique():
   movies.filter(where director == director)

or something similar.

Upvotes: 1

Daniel Weigel
Daniel Weigel

Reputation: 1137

nunique means "number of unique (values)" so it will return numbers, not values themselves.

Could you try instead ?

directors.unique()

Upvotes: 0

Related Questions