Home > Enterprise >  Counting unique values or lables in a dataset
Counting unique values or lables in a dataset

Time:04-12

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

CodePudding user response:

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.

CodePudding user response:

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

Could you try instead ?

directors.unique()
  • Related