Chapter1-Foundations For Efficiencies
Chapter1-Foundations For Efficiencies
1. Welcome!
Hello and welcome! My name is Logan Thomas, and I'll be your guide through this
course about writing efficient code using Python.
2. Course overview
As a data scientist, the majority of your time should be spent gleaning actionable
insights from data. Whether you're cleaning and curating a messy dataset, deploying
a machine learning model, or creating a sleek data visualization, the code you
write should be a helpful tool to quickly get you where you need to go - not
something that leaves you waiting around. In this course, you'll learn how to write
cleaner, faster, and more efficient Python code. We'll explore how to time and
profile your code in order to find potential bottlenecks. Then, you'll practice
eliminating these bottlenecks, and other bad design patterns, using Python's
Standard Library, NumPy, and pandas. After completing this course, you'll have
everything you need to start writing elegant and efficient Python code! But first,
let's explore what is meant by efficient Python code.
3. Defining efficient
In the context of this course, efficient refers to code that satisfies two key
concepts. First, efficient code is fast and has a small latency between execution
and returning a result. Second, efficient code allocates resources skillfully and
isn't subjected to unnecessary overhead. Although your definition of fast runtime
and small memory usage may depend on the task at hand, the goal of writing
efficient code is still to reduce both latency and overhead. For the remainder of
this course, we'll be exploring how to write Python code that runs quickly and has
little memory overhead.
4. Defining Pythonic
We've defined what is meant by efficient code, but it is also important to note
that this course focuses on writing efficient code using Python. Python is a
language that prides itself on code readability, and thus, it comes with its own
set of idioms and best practices. Writing Python code the way it was intended is
often referred to as Pythonic code. This means the code that you write follows the
best practices and guiding principles of Python. Pythonic code tends to be less
verbose and easier to interpret. Although Python supports code that doesn't follow
its guiding principles, this type of code tends to run slower. As an example, look
at the non-Pythonic code in this slide. Not only is this code more verbose than the
Pythonic version, it takes longer to run. We'll take a closer look at why this is
the case later on in the course, but for now, the main take away here is that
Pythonic code is efficient code!
Got It!
1. Building with built-ins
Python comes with a number of built-in components that you can think of as a
"batteries included" concept. Although these aren't exhaustive, they give us more
than enough to start using Python out-of-the-box. Let's explore a few built-in
components that help write efficient Python code.
Got It!
1. The power of NumPy arrays
NumPy, or Numerical Python, is an invaluable Python package for Data Scientists. It
is the fundamental package for scientific computing in Python and provides a number
of benefits for writing efficient code. In this lesson, we'll highlight one of the
most important advantages of NumPy: the NumPy array.
Got It!
1. The power of NumPy arrays
NumPy, or Numerical Python, is an invaluable Python package for Data Scientists. It
is the fundamental package for scientific computing in Python and provides a number
of benefits for writing efficient code. In this lesson, we'll highlight one of the
most important advantages of NumPy: the NumPy array.