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 Google Colab.
- Make sure you're using your school Google account. How to switch.
- Click
Copy to Drive.
That is now your own copy; make edits in there directly.
You'll create your own notebook.
- Read the instructions carefully. Like word problems from math class, they are very specific in what they are asking for.
- Ask for help.
- The assignments are meant to be challenging, not impossible.
- Try and work through problems on your own to start. If you are stuck for more than a half hour, step away. If you still can't figure it out, ask for help.
- Make variable names descriptive.
- Do as I say, not as I do!
- Only do one thing per line.
- Makes troubleshooting easier
- 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.
- Don't repeat yourself (DRY). If you find yourself copying and pasting code within your file(s), 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.
- Keep each cell to only a few lines of code.
- Allows/encourages you to output intermediate results, ensuring that everything is working as expected.
- 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.
- Make notebooks idempotent.
- Makes your work reproducible.
- Use
Restart session and run all(⏩ button in toolbar).
Generative AI tools can be incredibly useful, but the code they provide is often incomplete or wrong. Knowing enough about code to critically interpret their results can turn them from a crutch to a superpower.
For this course, it's recommended that you try doing the work yourself, asking the AI questions as needed when you're stuck/confused. If you're really lost, you can try:
- Having AI generate a solution.
- Try it.
- Copy it into a code cell.
- Run it.
- Confirm the output makes sense.
- Understand it.
- Read through it closely.
- Add a comment above each line explaining what it's doing.
- Redo it.
- Delete the code + comments from above.
- Close the AI chat.
- Re-write the solution yourself.
-
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 session and run all. - See general scoring criteria.
- This is a good time to run the notebook end-to-end with
-
Ensure the notebook doesn't contain any sensitive information. (Only really applicable to open-ended assignments.) This might include:
- API keys
- Personally-identifiable information (PII; data about individuals)
-
Download .ipynband.py(two files). -
Upload both files to the Gradescope Assignment.
Note the Final Project submission is slightly different.
- You can ignore Gradescope saying "Large file hidden". The file can be downloaded when grading.
- In-class exercises will not be submitted/graded.
-
Mounting Google Drive is slow or fails: See the Google Colab help page.
-
Can't load a file from Drive with
requests.get(): Useopen(). -
When using
choropleth()/choropleth_map(), nothing appears on the map: Make sure:- Your
locationscorresponds to the DataFrame column name andfeatureidkeyis set toproperties.<property name>matching the GeoJSON - The column and the GeoJSON properties have values that match
- Your
-
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 theRuntimemenu thenRestart Kernel. -
In a visualization, the values are out of order along the axis, or you're seeing vertical/zig-zag-y lines: Make sure that:
- The values are integers/floats/timestamps, not strings, where applicable. To convert, see:
- Line charts: The column used for the X axis is sorted.
-
AttributeError: partially initialized module 'orjson' has no attribute 'OPT_NON_STR_KEYS': Add the following cell before your other Plotly code, thenRestart session and run all.import plotly.io plotly.io.json.config.default_engine = 'json'
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.
- Get more memory in Colab:
- Sign up for free Colab Pro, if you haven't already.
- In the bottom-right corner, click
Python 3. - Click
Change runtime type. - Turn
High-RAM(Random Access Memory) on.
- Tweak pandas to use memory more efficiently.
- Make the dataset smaller.
