Skip to main content

Python Tracebacks

The Bottom Line Is Usually At The Bottom

Python errors often print several lines called a traceback. Read from the bottom upward:

FileNotFoundError: [Errno 2] No such file or directory: 'Data/patients.csv'

This tells you the immediate problem: Python cannot find the file at the path you gave it.

Common Week 5 Errors

Error Likely cause First fix
FileNotFoundError path is wrong, file is in another folder, or capitalization differs check the relative path from the notebook location
ModuleNotFoundError package is missing add the package to requirements.txt and install it in the Codespace
KeyError column name is misspelled or not present run nhanes.columns.tolist()
IndentationError Python block spacing is inconsistent re-indent the block with four spaces
NameError object has not been created in the current kernel rerun earlier cells in order

AI Debugging Prompt

Read this Python traceback from the bottom up. Identify the error type, the exact object or path causing the issue, and the smallest code change that would fix it. Do not rewrite the full analysis.

Student Check

When you fix an error, add one sentence to your notebook explaining what failed and how you knew the fix worked.