General assignment information#

Getting started#

To edit/execute a Homework/lecture notebook:

  1. Open the page for the Homework/Lecture on this site.

  2. Click the launch button (🚀) at the top.

  3. You should now see the notebook in Google Colab.

  4. Make sure you’re using your Columbia Google account. How to switch.

  5. Click Copy to Drive. That is now your own copy; make edits in there directly.

Tips#

  • 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#

To keep data between sessions, you’ll probably want to store it in Google Drive.

  1. Upload the file(s) somewhere in Drive.

  2. In the Colab sidebar, click the Files icon.

  3. Click the Mount Drive icon.

    • Think of this as attaching your Drive to your Colab instance, as if you were plugging in a USB flash drive.

  4. Navigate to the file.

  5. Next to the filename, click the three dots.

  6. Click Copy path.

    • The value should be something like /content/drive/My Drive/....

  7. Use this path with read_csv().

Reducing data size#

You can make data smaller before uploading by filtering it through:

Submission#

  1. Ensure all the outputs are visible and the notebook is cleaned up.

  2. Confirm that the notebook is shared with the instructor and Reader with Commenter permissions. If it isn’t, share the parent folder and re-confirm.

  3. Copy the URL of your notebook.

    • The URL should be of the format https://colab.research.google.com/drive/<long identifier>. If it’s https://colab.research.google.com/github/..., click Copy to Drive.

  4. Paste your notebook URL in the CourseWorks Assignment.

Engaging with comments left in Google Colab is more than welcome. After the late submission deadline for a given Homework passes, the solution will be shared.

Note: In-class exercises will not be graded.

Common issues#

  • Mounting Google Drive is slow or fails: See the Google Colab help page.

  • Can’t load a file from Drive with requests.get(): Use open().

  • When using choropleth_mapbox(), nothing appears on the map: Make sure:

    • Your locations corresponds to the DataFrame column name and featureidkey is set to properties.<property name> matching the GeoJSON

    • The column and the GeoJSON properties have values that match

  • SettingWithCopyWarning: How to fix

  • input() 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 the Runtime menu then Restart Kernel.

runtime/memory issues#

The runtime is the place where Python is installed and the code is actually executing, in the cloud somewhere.

  • If your runtime 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