Export the building violations data from 2016 thus far as CSV from the data portal:
Also download the community areas shapefile:
(Click Export... then click Shapefile)
Finally, download the nltk in python by running:
and then download the “stopwords” package from the All Packages tab.
Using QGIS, generate a heatmap of building violations overlaid on the community areas. Save the map as an image (Project > Save as Image) and include it in your solution repository.
Open the building violations data in python. The “VIOLATION INSPECTOR COMMENTS” field contains (uppercase!) free text describing each building violation.
Concatenate the non null inspector comments into one string.
Tokenize the inspector comments.
Apply the Porter stemmer.
What are the ten most common terms in the building violation inspector comments (after the above transformations)?
We will use the web interface to a pandas DataFrame we’ve been developing in class from the last lecture as a starting point:
We’ll examine this web app and then add a new page.
Recall from lecture that the code for our web application is stored in dfdisplay.py. Note that config.py contains the path to the CSV we’d like to display. The code in dfdisplay.py takes a CSV file and renders it as an HTML page:
return render_template('dataframe.html', data=df.to_dict(), cols=cols, nrows=len(df))
Try to run the application from the command line:
$ python dfdisplay.py
On the command line, it will produce output beginning with “ * Running on …”.
In a web browser, go to the address that is produced in the output (should be an ip:port tuple like 127.0.0.1:5000). As your web browser submits HTTP GET requests, the server running on the command line should log each one and produce output to the command line. Paste one of the lines of output you get in your response.
Look at templates/dataframe.html. We can run some code between
%}. This code is then processed by the Jinja2 template engine that Flask uses. Note that not all Python expressions are supported by the Jinja2 template engine. What syntax differences do you notice in the code in the template and regular Python?
We want to add a link that will take us to an “About” page. Add a new route in the Python code dfdisplay.py to accomplish this. Write a code stanza that routes ‘/about’ to the template about.html that exists in the templates/ directory. You should render this template and pass a string name that contains your name. Check that it works and that both pages render correctly. Copy this working webapp directory to your repo and commit.