'Counting total number of variables in a np.array

I have a dataset, within that dataset a column specifying the Location as States.

I am using jupyter notebook, numpy only.

The dataset is in an array.

I wanted to remove the duplicate states so I can count the number of states I have in the column.

I have to use np.unique.

Could you help me in how I can go about writing a code to find out the number of states I have? Removing the duplicates and just the total of states.

Thanks



Solution 1:[1]

location = dataset[:,2] #or whatever column you're selecting for location
np.unique(location)

Hope your states are numbers and not words

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 diana18