Now You Code 2: Syracuse Crime Data

In this second now you code you will explore the plot.ly engine in detail using Syracuse, NY FBI crime data.


In [ ]:
import plotly.plotly as py    
import plotly.graph_objs as go  
import cufflinks as cf
import pandas as pd

In [ ]:
crime = pd.read_csv('https://raw.githubusercontent.com/mafudge/datasets/master/crime/syracuse-crime-data-1985-2012.csv')
crime.sample(10)

In [ ]:
# Make a line plot of population over the years, using cufflinks crime.iplot()
# set the titles on x "Year, Y "Population" and cart title " Syracuse Population" 
# TODO: replace the ???? with appropriate values to render the chart
crime.iplot(kind = 'scatter', x = '????', y = '????', title='????',xTitle='????',yTitle='????')

In [ ]:
# Step 1:
# Now plot the same thing using plot.ly without cufflinks, again filling in the templates. Using plot.ly takes more effort but
# you have more control / flexibility over how the plots are rendered.
plot_data = [
    go.Scatter(x=crime['????'], y=crime['????'], mode="lines+markers", name="????", marker=dict(color='red')),
]

py.iplot({ 'data': plot_data,
            'layout': {
               'title': '?????',
               'xaxis': {
                 'title': '???'},
               'yaxis': {
                'title': '???'}
        }})

In [ ]:
# Step 2:
# Now create a line plot of "Robbery rate" versus "Motor vehicle theft rate" over time.
# NOTE: you will need two series in your plot_data

Interactive Plots

Finally write a program to ask for a crime metric like "Robbery" / "Burglary" / "Manslaughter" etc as input, then renders a plot of that metric over time as output !

Note: check to make sure the entered crime metric is in the list of Pandas columns before you attempt to plot. It might be a good idea to print the column names before you plot. if it is not a valid metric, you should print "That is not a crime metric"

Step 3: Problem Analysis

Inputs:

Outputs:

Algorithm (Steps in Program):


In [ ]:
## Step 4: Write code here

Step 5: Reflection

Reflect upon your experience completing this assignment. This should be a personal narrative, in your own voice, and cite specifics relevant to the activity as to help the grader understand how you arrived at the code you submitted. Things to consider touching upon: Elaborate on the process itself. Did your original problem analysis work as designed? How many iterations did you go through before you arrived at the solution? Where did you struggle along the way and how did you overcome it? What did you learn from completing the assignment? What do you need to work on to get better? What was most valuable and least valuable about this exercise? Do you have any suggestions for improvements?

To make a good reflection, you should journal your thoughts, questions and comments while you complete the exercise.

Keep your response to between 100 and 250 words.

--== Write Your Reflection Below Here ==--


In [ ]:
# RUN THIS CODE CELL TO TURN IN YOUR WORK!
from ist256.submission import Submission
Submission().submit()