From version 2.0 we hava our clenaed data with no rows and columns with total values we have pure data assoctated wth each crime bow lets sepearte all crimes individually
Note file name:
>>crimescleaned.csv
In [1]:
#Include libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
In [22]:
crimes = pd.read_csv('crimescleaned.csv', index_col=0)
crimes.head() #seems and unwanted column is added
Out[22]:
In [31]:
pd.unique(crimes['CRIME HEAD'])
Out[31]:
In [43]:
crimelist = pd.unique(crimes['CRIME HEAD'])
crimelist
Out[43]:
In [61]:
#rape,kidnapping = crimes[crimes['CRIME HEAD']=='RAPE'], crimes[crimes['CRIME HEAD']=='KIDNAPPING and ABDUCTION']
for crime in crimelist:
print crime
In [65]:
for crime in crimelist:
df = crimes[crimes['CRIME HEAD']== crime]
df.to_csv(crime+'.csv')
Now we have a seperate csv files with different crimes which we can load sperately whenever we want
In [74]:
import os
DIR_PATH = os.getcwd() + '//crimes'
In [75]:
DIR_PATH
Out[75]:
In [86]:
for filenames in (os.walk(DIR_PATH)):
for filename in filenames:
print filename
In [88]:
#This sounds Cool
for filename in os.listdir(DIR_PATH):
print filename
In [ ]: