<jupyter_start><jupyter_text>Data Exploration<jupyter_code>police_killings = pd.read_csv('police_killings.csv', encoding='ISO-8859-1')
police_killings.dtypes
police_killings.head()<jupyter_output><empty_output><jupyter_text>Does race matter?<jupyter_code>race_counts = police_killings['raceethnicity'].value_counts()
plt.bar(np.arange(race_counts.size), race_counts, align='center')
plt.xticks(np.arange(race_counts.size), race_counts.index, rotation='vertical', fontsize='large')
plt.show()
race_counts / np.sum(race_counts) * 100<jupyter_output><empty_output><jupyter_text>from the charts above, we found that about half of people been killed are white. Black people account for approximately one thirds.  Does regional income matter?<jupyter_code>income = police_killings[police_killings['p_income'] != '-']['p_income']
income = income.astype('float')
sns.distplot(income, kde=False)
sns.plt.show()
income.median()<jupyter_output><empty_output><jupyter_text>The figure above shows that the high police killing rate happen in the states that the median income are about 22,000 dollar.  Shootings By State In order to analyze the killing data by state, we need to know not only the number of people have been killed in each state, but also the population in each state.<jupyter_code>state_pop = pd.read_csv('state_population.csv')
state_pop.head()
state_counts = police_killings['state_fp'].value_counts()<jupyter_output><empty_output><jupyter_text>Creating a new Data Frame and combine with the state population, so that we can find out the killing rate.<jupyter_code>states = pd.DataFrame({'STATE': state_counts.index, 'shooting': state_counts})
states = states.merge(state_pop, on='STATE')
states.head()<jupyter_output><empty_output><jupyter_text>Convert the unit of population to millions.<jupyter_code>states['pop_millions'] = states['POPESTIMATE2015'] / 1000000
states['rate'] = states['shooting'] / states['pop_millions']<jupyter_output><empty_output><jupyter_text>Ordering `rate` column from highest to lowest.<jupyter_code>states[['STATE', 'shooting', 'NAME', 'pop_millions', 'rate']].sort_values('rate', ascending=False)<jupyter_output><empty_output><jupyter_text>From the chart above, we can wrap up. Generally speaking, states located in middle south have the heighest rate of police killing rate. However, the rate in northeast seem to be the lowest.  State By State Differences Which states have the highest number of police killing?<jupyter_code>states[['STATE', 'shooting', 'NAME', 'pop_millions', 'rate']].sort_values('shooting', ascending=False)
pk = police_killings[(police_killings['share_white'] != '-') & \
                     (police_killings['share_black'] != '-') & \
                     (police_killings['share_hispanic'] != '-')]
pk['share_white'] = pk['share_white'].astype('float64')
pk['share_black'] = pk['share_black'].astype('float64')
pk['share_hispanic'] = pk['share_hispanic'].astype('float64')<jupyter_output>/Users/yuzezou/anaconda/lib/python3.5/site-packages/ipykernel/__main__.py:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  if __name__ == '__main__':
/Users/yuzezou/anaconda/lib/python3.5/site-packages/ipykernel/__main__.py:2: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  from ipykernel import kernelapp as app
/Users/yuzezou/anaconda/lib/python3.5/site-packages/ipykernel/__main__.py:3: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the [...]<jupyter_text>We have to change state's name to its abbreviate name because there is no abbr name for state.<jupyter_code>lowest_states_list = ["CT", "PA", "IA", "NY", "MA", "NH", "ME", "IL", "OH", "WI"]
highest_states_list = ["OK", "AZ", "NE", "HI", "AK", "ID", "NM", "LA", "CO", "DE"]

lowest_states = pk[pk['state'].isin(lowest_states_list)]
highest_states = pk[pk['state'].isin(highest_states_list)]<jupyter_output><empty_output><jupyter_text>Comparing these columns by means of median.<jupyter_code>columns = ["pop", "county_income", "share_white", "share_black", "share_hispanic"]
lowest_states[columns].median()
highest_states[columns].median()<jupyter_output><empty_output><jupyter_text>In the states of the lower country income, the police killing rate are higher. By contrary, in the states of higher country income, the police killing rate is lower.   Let's find out the cause.<jupyter_code>causes = police_killings['cause'].value_counts()
causes.plot(kind='pie', autopct='%.2f', title='Cause', fontsize=16, figsize=(12,12))
plt.legend(labels=causes.index)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13156854998024498, 'fraction_numerical': 0.009087317265902806, 'mean_word_length': 6.87402799377916, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '623792', 'license': 'MIT', 'n_tokens_mistral': 1760, 'n_tokens_neox': 1659, 'n_words': 412, 'path': 'Police Killings/Police Killing.ipynb', 'repo_name': 'frankbearzou/Data-analysis', 'size': '5062'}