Who Do You Love?
Are Americans dog people or cat people?
An analysis of cats and dogs in the United States, from a publicly available dataset obtained from Kaggle.
This is my first attempt at my own data analysis project. I've compeleted some guided projects on DataCamp, and wanted to see how well I could do one on my own. I am, however, still a beginner.
This analysis will attempt to answer some questions about this dataset.
- What states have the most dog-owner households? What states have the most cat-owner households?
- What is the total dog and cat population by state?
- What is the total dog and cat population of the entire USA?
- What portion of households are pet-less households, cat-only households, dog-only households, and dog and cat households?
- Do Americans show a preference for one pet over the other?
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
pets = pd.read_csv('cats_and_dogs.csv')EDA
First I'll take a look at the dataset in order to see what information is in the rows and columns, and look for any missing values
pets.head()pets.info()Luckily, no missing values
pets.describe()Question 1
Which states own the most dogs? Which states own the most cats?
I will sort the rows based on the 'percent_dog_owners' columns in order to rank order the top dog-owning states. I'll do the same with the 'percent_cat_owners' column.
top_dog_states = pets.sort_values('percent_dog_owners', ascending=False).drop(index=pets.index[10:])
top_dog_statestop_cat_states = pets.sort_values('percent_cat_owners', ascending=False).drop(index=pets.index[10:])
top_cat_statesfig, ax = plt.subplots(1, 2, figsize=(12,4))
ax[0].bar(top_dog_states['state'], top_dog_states['percent_dog_owners'], color='lightblue')
ax[0].set_title('Top 10 dog owner states')
ax[0].set_xticklabels(top_dog_states['state'], rotation=75)
ax[0].set_xlabel('States with highest % of dog owners')
ax[0].set_ylabel('% of homes with dogs')
ax[1].bar(top_cat_states['state'], top_cat_states['percent_cat_owners'], color='lightcoral')
ax[1].set_title('Top 10 cat owner states')
ax[1].set_xticklabels(top_cat_states['state'], rotation=75)
ax[1].set_xlabel('States with highest % of cat owners')
ax[1].set_ylabel('% of homes with cats')
plt.show()Answer to Question 1: The graph shown above provides the top 10 dog-owning and cat-owning states in the USA. Dog-owner states have higher percentages of dog homes, than the cat-owner states.
Question 2
What is the total dog and cat population by state, and nationwide?