Debugging Workflow for Python Beginners in Data Science
By: Frank Flavell
Tags: Python3, Data Science, Python, Debugging, Programming

We’ve all been there. Staring at a screen full of code that’s not working and thinking, “whoever designed this language is seriously MESSING with me!”

But before you go down the rabbit hole of life’s regrets, take a step back and use this debugging checklist to get back on track.

The Debugging Mindset

Congratulate yourself! Despite the daunting complexity of a new programming language, you still gave it a try. For a beginner, that’s a victory in itself.

Despite the daunting complexity of a new programming language, you still gave it a try. For a beginner, that’s a victory in itself. Embrace the bug. This is your greatest opportunity to learn because once you fix the bug — and you will fix it — you’ll never forget the mistake. In fact, the more difficult the bug, the deeper it will be ingrained into your subconscious. Sweet dreams!

This is your greatest opportunity to learn because once you fix the bug — and you will fix it — you’ll never forget the mistake. In fact, the more difficult the bug, the deeper it will be ingrained into your subconscious. Sweet dreams! You’re not alone. The first programming bug was an actual moth found in the massive Harvard Mark II by Grace Hopper. You are only the latest in a long and storied lineage of metaphysical exterminator programmers. Stand on the shoulders of giants.

The first programming bug was an actual moth found in the massive Harvard Mark II by Grace Hopper. You are only the latest in a long and storied lineage of metaphysical exterminator programmers. Stand on the shoulders of giants. Don’t beat yourself up. Remember the main objective is to make something work. Getting angry at yourself won’t make your code work. But this process will.

Error Messages

Start with error messages. They’re your friends! But real friends who tell you when you’re making a mistake instead of the other people who let you fall on your face. Python is an extremely well documented language with error messages that get right to the point.

Common Errors

Type Error: There’s an issue with your data or collection types.

There’s an issue with your data or collection types. Name Error: There’s an issue with your variables.

There’s an issue with your variables. Syntax Error: There’s an issue with your syntax.

There’s an issue with your syntax. Value Error: There’s an issue with your arguments.

Read the error messages closely and they will tell you a lot about the issue. If you’re having trouble understanding the error, then look at the Python documentation or simply copy and paste the message in a search engine.

No Error Message!

If there’s no error message, then it means your code technically works, but its not printing your desired output. There’s either a problem with your code, your understanding of the data, and/or your overall logic for solving the problem.

Compare Current Output to the Desired Output

If you haven’t already, you should clearly describe your desired output. For example, what data type should it be? Compare your current output to the desired output and identify the key differences between the two.

Quick Code Check

A review of outputs should give you an idea for how to tweak the code. Use print() and type() functions to test each line of your code to make sure it’s doing what it should.

Review Data

If your code check doesn’t solve the issue, then take a second look at your data. A deeper understanding of your data can illuminate that you didn’t know enough yet to solve the specific problem your working on. For example, maybe a specific column of categorical data was encoded with numerical values, like 1 for New York, 2 for Connecticut, and 3 for New Jersey.

Update Your Logic

A better understanding of your data and your code will help you update your conceptual logic for how to solve the problem. If you’re really struggling, then step away from the screen and try writing out your solution in pseudo-code. Then check your pseudo-code against your actual code. If you still can’t figure it out, then at least you can clearly explain your logic to someone who might be able to help.

Ask a Friend or Mentor

Sometimes just talking through a problem with a friend or mentor can help you find the solution on your own. Sometimes you truly do need their input to expand your understanding of the code, data, and programming logic. Or if they can’t help you, maybe its time to find new friends. You can also use sites like stackoverflow to get the input of developers from around the world.