In [6]:
# Import Necessary Libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
% matplotlib inline
In [231]:
crimes = pd.read_csv('crcCAW.csv')
In [232]:
crimes.head()
Out[232]:
In [25]:
crimes.plot()
Out[25]:
The above Plot is not Satisfactory and is not accurate so lets look at data once again
In [28]:
crimes.head()
Out[28]:
Lets try Something different :
first extract Rape data in new dataframe
Note: Rape data in first 29 rows
In [34]:
crimes.values
Out[34]:
Lets try to sum up the all the crimes
In [47]:
year_wise_crime = crimes.ix[:,2:].sum(axes=1)
In [59]:
year_wise_crime
Out[59]:
In [65]:
year_wise_crime.plot(kind='bar', figsize=(8,5), legend=True, title='Number of Crimes per Year',)
Out[65]:
Yet another plot using Line
In [60]:
year_wise_crime.plot(kind='line')
Out[60]:
Making it more Beautful
In [121]:
year_wise_crime.columns = ['Crimes']
year_wise_crime
year_wise_crime.index.values
Out[121]:
In [126]:
year_wise_crime.plot(figsize=(10,5))
Out[126]:
In [94]:
year_wise_crime.plot(kind='bar')
Out[94]:
In [103]:
year_wise_crime.plot(kind='barh', figsize=(10,5))
Out[103]:
Now the Problem with above data is we have also summed up the total values did you notice the Total row name in Dataframe
Now we will try to get only rape data
In [233]:
crimes.head()
Out[233]:
In [234]:
rape = crimes[crimes['CRIME HEAD'] == 'RAPE']
rape
Out[234]:
In [149]:
totalrape = rape[rape['STATE/UT'] == 'TOTAL (ALL-INDIA)']
totalrape
Out[149]:
In [185]:
#df1.iloc[1:5,2:4]
totalrape2 = totalrape.iloc[:,2:].T
In [190]:
totalrape2
totalrape2.index.name = 'Year'
totalrape2.columns = ['No. of Crimes']
totalrape2
Out[190]:
In [235]:
totalrape2.plot(figsize=(8,5), title='Number of Rapes per Year\n in India')
Out[235]:
The above is the final Diagram on rape in india
In [239]:
totalcrimes = crimes[crimes['CRIME HEAD'] == 'TOTAL CRIMES AGAINST WOMEN']
totalcrimes.head()
Out[239]:
In [240]:
totalcrimes1 = totalcrimes[totalcrimes['STATE/UT'] == 'TOTAL (ALL-INDIA)']
In [241]:
totalcrimes1
Out[241]:
In [245]:
finaltotalcrimes = totalcrimes1.iloc[:,2:]
finaltotalcrimes
Out[245]:
In [246]:
finaltotalcrimes = finaltotalcrimes.T
In [249]:
finaltotalcrimes.index.name = 'Year'
finaltotalcrimes.columns = ['TOTAL CRIMES AGAINST WOMEN']
finaltotalcrimes
Out[249]:
In [252]:
plt = finaltotalcrimes.plot(figsize=(7,5), title='Total Crimes Against Women per Year\n In India ')
In [254]:
bar = finaltotalcrimes.plot(kind = 'bar',figsize=(8,5), title='Total Crimes Against Women per Year\n In India ')
In [ ]:
#to drop rows ::df.drop(df.index[[1,3]])