Data scientists and AI engineers love to work with Jupyter Notebooks because they make so much easier to look at the result of each and every data exploration step or data modeling experiment and make decisions accordingly.
However, Jupyter notebooks are not immune to errors, and sometimes understanding error messages - in particular if you aren’t a native English speaker or you are a beginner - and troubleshooting code might be painful and time-consuming.
In this video below I share some tips and tricks on how to leverage VSCode and GitHub Copilot to increase your productivity, making it easier to analyze and fix the most common Python errors in Jupyter notebooks.
The code shown in this video is hosted in a GitHub repo.
In the demo repo, you also have the option of running the Jupyter notebook on GitHub Codespaces.
This video covers 3 types of common errors when working with Python in Jupyter Notebooks.
1. Indentation Error
Whereas in other programming languages the indentation in code is for readability only, the indentation in Python is very important. Python uses indentation to indicate a block of code, so you have to use the same number of spaces in the same block of code, otherwise Python will give you an error, like in the example below.
2. Module Not Found Error
When you try to import in your code a library that is not installed in your development environment, you'll encounter a ModuleNotFound error. In our example below, we are trying to use the seaborn library, which is not installed in our venv.
3. Name Error
NameError usually occurs when you try to use a variable that has not been defined before usage or it's out of scope. Sometimes it can be due simply to a typo, making the variable name declared and used not match, as in the code cell below.
GitHub Copilot Features
This demo leverages some of the GitHub Copilot features available in VS Code to troubleshoot and fix the errors above:
Inline suggestions: GitHub Copilot completes your code and markdown cell content as you type
Chat: GitHub Copilot offers a chat experience (both inline and in the sidebar) to get assistance in VS Code, avoiding context-switching