text_plain_output_1.png image_output_1.png
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

## Rate of crimes solved
solved = pd.DataFrame(data, columns = ['Crime Solved']) 
resolution = solved.stack().value_counts()
ax = resolution.plot(kind = 'pie',
                              title = 'Crimes solved between 1980 & 2014 (in %)',
                              startangle = 10,
                              autopct='%.2f')
ax.set_ylabel('')

#Gender of victims
sex = pd.DataFrame(data, columns = ['Victim Sex']) 
count_sex = sex.stack().value_counts()
ax = count_sex.plot(kind = 'pie',
                              title = 'Sex of the victims',
                              startangle = 10,
                              autopct='%.2f')
ax.set_ylabel('')

#Race of Victims
race = pd.DataFrame(data, columns = ['Victim Race']) 
count_race = race.stack().value_counts()
ax = count_race.plot(kind = 'pie',
                              title = 'Race of the victims',
                              startangle = 10,
                              autopct='%.2f',
                              explode=(0, 0, 0.7, 1, 1.3))
ax.set_ylabel('')

data['Victim Age'] = data['Victim Age'].astype('int')
mask = data['Victim Age'] < 21
young_victims = pd.DataFrame(data.loc[mask], columns=['Year'])
count_years = young_victims.stack().value_counts()
homicides_young = count_years.sort_index(axis=0, ascending=False)
mask2 = data['Victim Age'] > 21
adult_victims = pd.DataFrame(data.loc[mask2], columns=['Year'])
count_years = adult_victims.stack().value_counts()
homicides_adult = count_years.sort_index(axis=0, ascending=False)
print(homicides_young.plot(kind='barh', fontsize=10, width=0.5, figsize=(12, 10), title='Victims under 21 years old'))