From the course: Python Data Science Mistakes to Avoid
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Not importing relevant libraries and modules - Python Tutorial
From the course: Python Data Science Mistakes to Avoid
Not importing relevant libraries and modules
- [Instructor] A common mistake that can come up when using modules in libraries in your code is not importing them first. For example, let's say that I want to take the square root of a number. So I call the SQRT function from Python's math library like this. As you can see, when I ran the cell, I got a name error that says name math is not defined. This is because I did not import the math library before referring to its SQRT function. To fix this, I can add a cell above in which I import math. As you can see, when I rerun the cells everything worked and there were no errors. So make sure you remember to import all relevant libraries and modules first before you try to access specific functions from them.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
(Locked)
Not writing comments3m 11s
-
(Locked)
Not organizing your directory3m 11s
-
(Locked)
Not testing2m 36s
-
(Locked)
Not sharing data referenced in code1m 10s
-
Hard coding inaccessible paths3m 10s
-
Name clashing with Python standard library2m 26s
-
(Locked)
Not importing relevant libraries and modules43s
-
(Locked)
Naming vaguely1m 51s
-
(Locked)
-
-
-
-