Make money doing the work you believe in

When I started with Python, I was scared of error messages.

Not because I did not understand the code. Because the red text felt very dramatic.

It took me a while to realise errors are the most useful thing Python does — they tell you precisely where the problem is and why.

Here are the 10 errors every data analyst will see, what they actually mean, and how to fix them:

𝗦𝘆𝗻𝘁𝗮𝘅𝗘𝗿𝗿𝗼𝗿 — Python cannot read what you wrote. Usually a missing bracket, quote, or colon. Read the line above the arrow. That is where the mistake is.

𝗜𝗻𝗱𝗲𝗻𝘁𝗮𝘁𝗶𝗼𝗻𝗘𝗿𝗿𝗼𝗿 — Your spacing is wrong. Use 4 spaces consistently. Never mix tabs and spaces.

𝗡𝗮𝗺𝗲𝗘𝗿𝗿𝗼𝗿 — You used a variable before defining it. Define before you use. Always.

𝗧𝘆𝗽𝗲𝗘𝗿𝗿𝗼𝗿 — You mixed incompatible data types. Convert types before combining them. str(), int(), float() are your first tools.

𝗞𝗲𝘆𝗘𝗿𝗿𝗼𝗿 — You asked for a dictionary key that does not exist. Use .get() instead of square brackets to avoid crashes on missing keys.

𝗜𝗻𝗱𝗲𝘅𝗘𝗿𝗿𝗼𝗿 — You asked for a list position that does not exist. Lists start at 0. The last item is index -1.

𝗔𝘁𝘁𝗿𝗶𝗯𝘂𝘁𝗲𝗘𝗿𝗿𝗼𝗿 — You called a method that does not exist on that object. Check the type first. df.dtypes is your friend.

𝗩𝗮𝗹𝘂𝗲𝗘𝗿𝗿𝗼𝗿 — Right type, wrong value. Use pd.to_numeric(errors='coerce') to handle bad values without crashing.

𝗜𝗺𝗽𝗼𝗿𝘁𝗘𝗿𝗿𝗼𝗿 — The library is not installed or the name is wrong. In Colab use !pip install. Locally use pip install in terminal.

𝗙𝗶𝗹𝗲𝗡𝗼𝘁𝗙𝗼𝘂𝗻𝗱𝗘𝗿𝗿𝗼𝗿 — The file path is wrong. Use os.getcwd() to see where Python is looking, then adjust your path.

Errors are not failures. They are Python telling you exactly what went wrong.

Jun 8
at
12:00 PM
Relevant people

Log in or sign up

Join the most interesting and insightful discussions.