CSV and Pandas

Download a csv containing information about abandoned buildings in Chicago from here. (Click on export ->csv.) (or click here)

We will open and examine the dataset using Pandas.read_csv()

  • We will learn lots more about Pandas later.
In [2]:
import pandas 
df = pandas.read_csv('311_Service_Requests_-_Vacant_and_Abandoned_Buildings_Reported.csv',low_memory=False)
df.head()
Out[2]:
SERVICE REQUEST TYPE SERVICE REQUEST NUMBER DATE SERVICE REQUEST WAS RECEIVED LOCATION OF BUILDING ON THE LOT (IF GARAGE, CHANGE TYPE CODE TO BGD). IS THE BUILDING DANGEROUS OR HAZARDOUS? IS BUILDING OPEN OR BOARDED? IF THE BUILDING IS OPEN, WHERE IS THE ENTRY POINT? IS THE BUILDING CURRENTLY VACANT OR OCCUPIED? IS THE BUILDING VACANT DUE TO FIRE? ANY PEOPLE USING PROPERTY? (HOMELESS, CHILDEN, GANGS) ... ADDRESS STREET SUFFIX ZIP CODE X COORDINATE Y COORDINATE Ward Police District Community Area LATITUDE LONGITUDE Location
0 Vacant/Abandoned Building 08-00109075 01/18/2008 NaN NaN NaN NaN NaN NaN NaN ... ST 60613.0 NaN NaN NaN NaN NaN NaN NaN NaN
1 Vacant/Abandoned Building 08-00577896 04/03/2008 NaN NaN Building is Open / Unsecure NaN Vacant NaN NaN ... ST 60621.0 1.170179e+06 1.858859e+06 17.0 7.0 68.0 41.768198 -87.651771 (41.76819814695611, -87.65177097869127)
2 Vacant/Abandoned Building 08-00588295 04/05/2008 NaN NaN Building is Open / Unsecure GARAGE, VAGRANTS BROKE INTO GARAGE AND USE IT ... Vacant NaN True ... AVE 60619.0 1.182657e+06 1.850683e+06 6.0 6.0 44.0 41.745482 -87.606287 (41.745482414802325, -87.60628681474407)
3 Vacant/Abandoned Building 08-01476976 07/30/2008 NaN NaN Building is Open / Unsecure REAR Vacant NaN NaN ... AVE 60621.0 1.174523e+06 1.857609e+06 6.0 7.0 68.0 41.764674 -87.635884 (41.764673747551555, -87.63588403606937)
4 Vacant/Abandoned Building 08-01559367 08/07/2008 NaN NaN Building is Open / Unsecure FRONT AND REAR Vacant NaN NaN ... ST 60636.0 1.169023e+06 1.855703e+06 17.0 7.0 67.0 41.759564 -87.656096 (41.75956423181548, -87.65609637199394)

5 rows × 23 columns

In [8]:
%pylab inline
fig = plt.figure()
plot(df['LONGITUDE'],df['LATITUDE'],'.',markersize=1,alpha=0.01)
xlim(-87.9, -87.5)
ylim( 41.6,  42.1)
Populating the interactive namespace from numpy and matplotlib
Out[8]:
(41.6, 42.1)
In [7]:
R = 3959 # Question: What is this number?
fig = plt.figure()
ax = fig.add_subplot(111,aspect=1.0)
plot(R*cos(41.8*pi/180)*df['LONGITUDE']*pi/180,R*df['LATITUDE']*pi/180,
     '.',markersize=1,alpha=0.01)
xlim(-4525, -4505)
ylim(2875, 2905)
Out[7]:
(2875, 2905)

Compare this to the map of chicago

In [6]:
from IPython.display import Image
Image('abandoned_plot2.png',width=600)
Out[6]: