General assignment information#
Getting started#
To edit/execute a Homework/lecture notebook:
Open the page for the Homework/Lecture on this site.
For example: Homework 0
Click the launch button (🚀) at the top.
You should now see the notebook in JupyterHub. That is now your own copy; make edits in there directly.
Tips#
All lecture slides and homework templates can be found under
python-public-policy/
. The contents of this directory will be automatically updated from the GitHub repository, but should keep any changes you make.Access JupyterHub via the links on this site rather than bookmarking JupyterHub, as that will pull down the latest changes.
Read the instructions carefully. Like word problems from math class, they are very specific in what they are asking for.
Spot check your results. If you are transforming data from a previous Step, compare the results, do a handful of the calculations manually, etc. to ensure that the results are correct.
You are always welcome to add cells. You probably don’t want more than a few lines of code in each. This makes the spot checking of intermediate results easier.
Don’t repeat yourself (DRY). If you find yourself copying and pasting code within a notebook, there’s probably a better way to do it.
Avoid hard-coding values. Don’t rely on things like row numbers or column order being stable, in case the dataset were to be updated.
Storing data#
Open the JupyterHub file browser.
Navigate to the folder your notebook is in.
From Python, use
read_csv("./<filename>.csv")
.
Note that that file path should be to relative to the notebook within JupyterHub — ./
means “in the same directory”. JupyterHub cannot access the file on your local machine; in other words, the path shouldn’t start with C:\\
or anything like that. More info about file paths
Limits#
JupyterHub has a disk storage limit of 1GB (a.k.a. 1,024 MB or 1,048,576 KB) across all your files, and a memory limit of 3GB.
Reducing data size#
You can make data smaller before uploading by filtering it through:
The data portal, if it supports it
In a spreadsheet program
For the NYC Open Data Portal, though the shortener widget
Submission#
Ensure all the outputs are visible and the notebook is cleaned up.
This is a good time to run the notebook end-to-end with
Restart and run all
(⏩).
Export the notebook as a PDF. From the Jupyter interface, go to:
File
Save and Export Notebook As…
PDF
You may need to allow popups
Glance through the PDF to ensure everything is showing up as you intend.
In particular, check your visualizations.
What you see is what the instructors will see.
If one of the Homeworks: Upload the PDF to the Brightspace Assignment.
If the Final Project:
In Brightspace, go to
Content
, thenFinal Project
. You should see the TurnItIn/PeerMark dashboard.Follow these instructions to upload the PDF.
When you’re ready to have it formally re-graded, please resubmit through the same Assignment in Brightspace.
After the resubmission deadline passes for each Assignment, the solutions will be posted in shared/solutions/
.
Note: In-class exercises will not be graded.
Common issues#
PDF export:
500 error: You may be outputting too much data. Try reducing your output (in the Jupyter sense) to smaller subsets. This can include:
Not displaying so many rows/values
Reducing the number of points that are plotted
When using
choropleth_mapbox()
, nothing appears on the map: Make sure:Your
locations
corresponds to the DataFrame column name andfeatureidkey
is set toproperties.<property name>
matching the GeoJSONThe column and the GeoJSON properties have values that match
SettingWithCopyWarning
: How to fixinput()
stuck: Jupyter can be a bit buggy when dealing with interactive input. If it seems to get stuck or you aren’t seeing a prompt when you’d expect one, try clicking theKernel
menu thenRestart Kernel
.
Disk full#
If you get an error of Disk is full
/ No space left on device
/ Out of diskspace
: You’ve used all the available disk space. If you do fill it up, your server may not be able to start again (spawn failed
). You’ll need to delete one or more large files that you don’t need anymore:
If you server is started already (you’re seeing notebooks), click
Control Panel
->Stop My Server
.Go to start your server again from padmgp-4506-fall.rcnyu.org.
Select
Troubleshooting Only - Clear Disk
.Look at the
File size
Jupyter shows in the file browser.Delete one or more large files.
If you’re still using those datasets, make them smaller.
Error loading notebook
#
This error can happen if you tried to output a lot of data in tables/charts. Steps to resolve:
Open the JupyterHub) file browser
Click
New
, thenTerminal
Run the following, changing the path at the end to match whatever notebook needs to be repaired:
jupyter nbconvert --to notebook --clear-output ~/python-public-policy/hw_<NUMBER>.ipynb
If you’re confused by these instrucions, download the notebook file and email to the instructor.
kernel/memory issues#
The kernel is the place where Python is installed and the code is actually executing, in the cloud somewhere.
Make sure
Python [conda env:python-public-policy]
is selected as the kernel.Shows in the top right of the notebook interface
To change:
Open the
Kernel
menuClick
Change kernel
Click
Python [conda env:python-public-policy]
If your kernel is repeatedly crashing, you’re probably running out of memory.
Make sure you aren’t loading data sets you don’t need.
If loading a new dataset, make it smaller
Close kernels you aren’t using from the Running page.