<jupyter_start><jupyter_text>2018 Detroit Crime Data Analysis---An exploratory data analysis was performed on Detroit's Crime Data available through the City of Detroit's Open Portal resource website. Pandas Python was the software used to conduct the analysis.DPD Crime Data was downloaded from Open Portal, stored in OneDrive, and uploaded to Google Colab notebook for analysis.https://data.detroitmi.gov/Public-Safety/DPD-All-Crime-Incidents-December-6-2016-Present/6gdg-y3kf<jupyter_code>import pandas as pd
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns

# Retrieve the data into a Pandas DataFrame.
dpd_crime = pd.read_csv('Detroit_Police_Incidents_2018.csv')<jupyter_output>/usr/local/lib/python3.6/dist-packages/IPython/core/interactiveshell.py:2718: DtypeWarning: Columns (6,12,13) have mixed types. Specify dtype option on import or set low_memory=False.
  interactivity=interactivity, compiler=compiler, result=result)<jupyter_text>Data Cleaning Detroit Crime Data cleaning was carried out in two steps using Excel to clean the structured data.Step 1: Began in Excel by changing the column's names from uppercase to lowercsae, eliminating several columns that were not needed, and replaced spaces with underscores.Step 2: Removed all columns<jupyter_code># Get some summaries of columns and data types.
print(dpd_crime.info())
print(dpd_crime.head())<jupyter_output>Crime ID    Report #  ...      date month
0   3313139  1901010180  ...  12/31/18    12
1   3307712  1901010143  ...  12/31/18    12
2   3307592  1901010009  ...  12/31/18    12
3   3307579  1901010024  ...  12/31/18    12
4   3307608  1901010003  ...  12/31/18    12

[5 rows x 22 columns]<jupyter_text>Question how many unique crimes, offense categories, and time of day crimes are there?It is interesting to find the total number of runaway offenses from 2016 (757) and the total number of assaults (23,717) are staggering.<jupyter_code>dpd_crime.head()
print(len(dpd_crime['Crime ID'].unique()))
print(len(dpd_crime['Offense Description'].unique()))
print(len(dpd_crime['Offense Category'].unique()))
crime_groups = dpd_crime.groupby(['Offense Description'], as_index=True)

# size gives the number of crimes descriptions.
print(crime_groups.size())
crime_groups = dpd_crime.groupby(['Offense Category'], as_index=True)

# size gives the number of Offenses Categories
print(crime_groups.size())
crime_count = pd.DataFrame(dpd_crime.groupby('Offense Category').size().sort_values(ascending=False).rename('counts').reset_index())
crime_count.head(10)
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="whitegrid")

# Initialize the matplotlib figure
f, ax = plt.subplots(figsize=(6, 15))


# Plot the total crashes
sns.set_color_codes("pastel")
sns.barplot(x="counts", y="Offense Category", data=crime_count.iloc[:10, :],
            label="Total", color="b")

ax.legend(ncol=2, loc="lower right", frameon=True)
ax.set(ylabel="Type",
       xlabel="Crimes")
sns.despine(left=True, bottom=True)

# Add a legend and informative axis label
plt.show()
crime_groups = dpd_crime.groupby(['Day of Week (Sunday is 1)'], as_index=True)

# size gives the number of crimes on each day.
print(crime_groups.size())
crime_groups = dpd_crime.groupby(['Hour of Day'], as_index=True)

# size gives the number of crimes per each hour of the day.
print(crime_groups.size())<jupyter_output>Hour of Day
0     5744
1     3270
2     2727
3     2431
4     1807
5     1596
6     1333
7     1627
8     2445
9     2907
10    3265
11    3250
12    4640
13    3514
14    3594
15    4084
16    4242
17    4261
18    4215
19    3916
20    4085
21    4138
22    4208
23    3955
dtype: int64<jupyter_text>ObservationFrom the data, crimes are distributed evenly though out the week with the highest concentration taking place around midnight.   Question how many crimes are committed throughout the day?<jupyter_code>dpd_crime['Offense Category'].value_counts().plot(kind = 'pie',autopct='%1.1f%%',figsize=(6,6))
plt.title('% of Total Crimes by Offense Category')
plot1 = dpd_crime.groupby('Hour of Day').size().reset_index(name='# of Crimes').set_index('Hour of Day')
plot1
plot1.plot(kind="line",figsize=(20,10), linestyle='--', marker='o')<jupyter_output><empty_output><jupyter_text>Plot ObservationAs expected we see in the box plot an even distribution of crime taking taking thoughout the 24 hour cycle.A Pie chart displays the same data next:<jupyter_code>dpd_crime["Hour of Day"].plot.box();
dpd_crime["Day of Week (Sunday is 1)"].plot.box();<jupyter_output><empty_output><jupyter_text>Question what is the correlation among data in the table?The correlation indicates and confirms that there is little to no correlation exists between the variables.<jupyter_code>dpd_crime.corr()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10070744902205576, 'fraction_numerical': 0.0690803162713275, 'mean_word_length': 4.9788557213930345, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '628987', 'license': 'MIT', 'n_tokens_mistral': 1780, 'n_tokens_neox': 1543, 'n_words': 490, 'path': 'DPD_All_Crime_Incidents_2018.ipynb', 'repo_name': 'kyle-w-brown/2018-Detroit-Crime-Report', 'size': '4806'}