14.7 Cats by gender in each locality
Our goal in this section is to create and plot a DataFrame containing the number of female and male cats per locality. We begin with a version of building the DataFrame via comprehensions.
The unique function returns a numpy array of the unique values in a pandas column.
localities = df["Locality"].unique()
localities
array(['DANDENONG NORTH', 'DANDENONG', 'SPRINGVALE', 'SPRINGVALE SOUTH',
'KEYSBOROUGH', 'NOBLE PARK NORTH', 'NOBLE PARK', 'BANGHOLME',
'DANDENONG SOUTH', 'LYNDHURST'], dtype=object)
type(localities)
numpy.ndarray
To make it easier for users to understand the results, we put the localities in alphabetical order. The numpy sort method sorts an array in place.
localities.sort()
localities
array(['BANGHOLME...