# Start (as usual) by loading libraries
import numpy as np
import pandas as pd
import matplotlib as mplib
import matplotlib.pyplot as plt

Error Messages and Documentation#

We’ve discussed many basics for using Python for data analysis, but there is so much more that Python can do. It would be extremely difficult, even impossible, to memorize all of the different functions and remember how to do everything. Luckily, there is plenty of documentation available so that you can figure out what to do even if you don’t remember it.

Error Messages#

Let’s start by looking at error messages. The following code has intentionally been written incorrectly to produce an error message.

print('Here is some text'
  Cell In[2], line 1
    print('Here is some text'
                             ^
SyntaxError: unexpected EOF while parsing

The important thing to look for in an error message is usually the last line. Here, we see “SyntaxError: Unexpected EOF while parsing”. This means that Python expected some more code, but it ended. This is because we forgot the close parenthesis.

print('Here is some text')
Here is some text

There might be times when you aren’t able to figure out what went wrong based on the last line. In that case, your best bet is to copy and paste that line containing the error message into Google and see if there are any helpful hints online. One great resource is Stack Overflow, a website in which users submit questions to get help about coding. You’ll most likely be able to find previous users who had the same issue you did, so you can simply find the appropriate thread and read what others have responded.

Documentation#

You can also get help by using the help function to look at the documentation. Let’s pull up the documentation for mean.

help(np.mean)

If this is a bit difficult to read (and it probably is because it’s in the same document as everything else), you can also look up the documentation online. We can see here what the source of our error was, because the parameter we need to specify is a, which is an array, or array-like object.

Checkpoint: Exploring Error Messages and Documentation #

Try looking at the documentation for various functions or objects we’ve gone over. This should help you get a better feel for how the documentation is structured, since you should have an idea what they’re like already. Some possibilities include:

  • Data Frames

  • print

  • type

Is there a part of the documentation that doesn’t make sense to you? Does seeing the documentation help you understand what you’re working with better?