<jupyter_start><jupyter_text>Homework 3  - Tryout pandas and numpyCopy this notebook. Rename it as: YOURNAME-Homework-panda-numpy-Sept-2017with your name replacing yourname and  replaced with the date you submit or to the last part.Do the homeworks problems below.Upload your completed jupyter notebook to your github site and send me the url via the elearning site as your homework submission. Please note that you need to do your own 3.4, and 3.5 if you share data and analysis from others then you cannot get more than a 3.    Homework 3.1 3.1.aLoad the data from: http://opendata.dc.gov/datasets that I have include in this github   into a dataframe.  ( The file has been is available in directory ./data/ccp_current_csv.csv )<jupyter_code>import pandas as pd
import numpy as np
data = pd.read_csv("data/ccp_current_csv.csv")
data<jupyter_output><empty_output><jupyter_text>3.1.a  what is its shape and what does that mean?<jupyter_code>data.shape
#it tells us that how many rows and columns in the data<jupyter_output><empty_output><jupyter_text>Homework 3.2 What are the number of rows in each 'QUADRANT' ?<jupyter_code>#465
q_id = data['QUADRANT']
data_newind = data.copy()
data_newind.index = q_id
data_newind.index.is_unique
pd.Series(data_newind.index).value_counts()<jupyter_output><empty_output><jupyter_text>Homework 3.3 - Array math demonstration For two arrarys  a= [1,2,3,4]  type=floatb= [5,6,7,8]  type=floatPeform the following array operations using numpy   ( show both operational use of numpy and functional (example addition operation => + vs addition function => numbpy.add() ) 3.3.1 addition a+b<jupyter_code>from numpy import *
a = array([1,2,3,4])
b= array([5,6,7,8])
a=np.array([1,2,3,4],dtype = np.float)
b=np.array([5,6,7,8],dtype = np.float)
print a+b
print np.add(a,b)
np.add(a,b)<jupyter_output><empty_output><jupyter_text>3.3.2 subtraction a-b<jupyter_code>a-b
np.subtract(a,b)<jupyter_output><empty_output><jupyter_text>3.3.3 multiplication a*b<jupyter_code>a*b
np.multiply(a,b)<jupyter_output><empty_output><jupyter_text>3.3.4 divsion a/b<jupyter_code>a/b
np.divide(a,b)<jupyter_output><empty_output><jupyter_text>3.3.5 modulo  a%b<jupyter_code>a%b
np.remainder(a,b)<jupyter_output><empty_output><jupyter_text>3.3.6 power  a^b<jupyter_code>a**b
np.power(a,b)<jupyter_output><empty_output><jupyter_text>Homework 3.4Find your own data and load it into a dataframe<jupyter_code>crimedata=pd.read_csv('data/Chicago_2017.csv')
print "The crime data of Chicago in 2017"
crimedata<jupyter_output>I load the crime data of Chicago in 2017<jupyter_text>Homework 3.5Provide an interesting analysis of the data columns ( frequency or averages )<jupyter_code>#calcualte the number of crime in Chicago 2017,average crime number, frequence every 1,000 people
print "There are %d crimes in year 2017"%(len(crimedata))
print "The average crime number in 2017 is %f"%(len(crimedata)/365.0)
print "The population in Chicago is about 2.7 million, so the crime frequency every thousand people is:%f"%(len(crimedata)/2700.0)
xs=crimedata['Primary Type'].value_counts()
print("Top 3 types of crime:")
print(xs[:3])
print("\nLeast 3 types of crime:")
print(xs[-3:])
data1=crimedata.loc[:,['Primary Type','Description','Location Description','Arrest']]
xs3=xs.sort_index() #sort all the crimes by name
xs1=data1[data1.Arrest==True] #get sub series where arrest is true
xs2=xs1['Primary Type'].value_counts()
xs2=xs2.sort_index() #sort by name
xs2/=xs3
xs2=xs2.sort_values(ascending=False) #sort by value,desending order
print "Top ten arrest rate of crimes:"
print xs2[:10]
import matplotlib.pyplot as plt
crimedata=pd.read_csv('data/Chicago_2017.csv',usecols=['Date','Domestic'],parse_dates=['Date'])
month=crimedata.Date.dt.month  #get month
his=crimedata['Domestic'].groupby(month).sum()  #get sum for 'Domestic' true and false
his2=hour.groupby(month).size()  #sum as a whole
his2=his/his2
his2=his2.reset_index()
his2.columns=['Month','Domestic Propotion']
print "This is a plot where the x-axis is Month and the y-axis is the proportion of crimes occuring that are domestic"
%matplotlib inline
his2.plot(x='Month',y='Domestic Propotion',kind='line')
print "The number of crime in each month:"
crimedata.Date.dt.month.hist(bins=12)
print "The number of crime in each hour:"
crimedata.Date.dt.hour.hist(bins=24)<jupyter_output>The number of crime in each hour:
StarcoderdataJupyterStructuredCleanDedup