<jupyter_start><jupyter_text>I am importing the csv. I could also use Urllib to pull form url but I like csv's. I limited the rows as I kept getting an error in row 131,000.<jupyter_code>nRowsRead=100000
badstuff= pd.read_csv('Crimes.csv',nrows=nRowsRead, index_col='INC NUMBER')<jupyter_output><empty_output><jupyter_text>I wanted all the columns to be lower case and spaces to be replaced by _. I used this replace method for it.<jupyter_code>badstuff.columns = badstuff.columns.str.strip().str.lower().str.replace(' ', '_').str.replace('(', '').str.replace(')', '')<jupyter_output><empty_output><jupyter_text>I am going to see the info and describe methods to get a better idea of the data.<jupyter_code>badstuff.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
Index: 100000 entries, 201600000052855 to 201700000927237
Data columns (total 6 columns):
 #   Column              Non-Null Count   Dtype  
---  ------              --------------   -----  
 0   occurred_on         99739 non-null   object 
 1   occurred_to         71048 non-null   object 
 2   ucr_crime_category  100000 non-null  object 
 3   100_block_addr      100000 non-null  object 
 4   zip                 99997 non-null   float64
 5   premise_type        99372 non-null   object 
dtypes: float64(1), object(5)
memory usage: 5.3+ MB<jupyter_text>After performing the describe, I realize its the only column with floats. Hence why its the only one that appears.<jupyter_code>badstuff.describe()<jupyter_output><empty_output><jupyter_text>I want to see how many different zip codes and different places their are for this data.<jupyter_code>badstuff.zip.value_counts()
badstuff.premise_type.value_counts()<jupyter_output><empty_output><jupyter_text>Now I want to sort the data. I am going to sort based on place.<jupyter_code>badstuff.sort_values(by=['premise_type','ucr_crime_category'])<jupyter_output><empty_output><jupyter_text>I am going to look at the different premises and which types of crimes are most common in each.<jupyter_code>places =badstuff.groupby('premise_type')
places.describe()<jupyter_output><empty_output><jupyter_text>Import matplotlib to make graphs eventually<jupyter_code>import matplotlib  as plot<jupyter_output><empty_output><jupyter_text>Want to graph the 10 highest areas of crime in the Phoenix area.<jupyter_code>places.zip.count().sort_values(ascending=False).iloc[1:10].plot.bar()<jupyter_output><empty_output><jupyter_text>Try and make a pie chart for crime in the top 10 areas of crime.<jupyter_code>tally= places.zip.count().sort_values(ascending=False).iloc[1:10]
tally
tally.plot.pie()
places.get_group('APARTMENT')
places.get_group('APARTMENT').nunique()<jupyter_output><empty_output><jupyter_text>Isolate the counts of crime category and graph it.<jupyter_code>places.get_group('APARTMENT').groupby('ucr_crime_category').zip.count()
places.get_group('APARTMENT').groupby('ucr_crime_category').zip.count().plot.bar(title='Apartment Crimes')<jupyter_output><empty_output>