Skip to main content

Writing Efficient Python Code

Learn to write efficient code that executes quickly and allocates resources skillfully to avoid unnecessary overhead.

Start Course for Free
4 Hours15 Videos53 Exercises70,178 Learners4050 XPData Engineer TrackPython Programmer TrackPython Programming TrackPython Toolbox Track

Create Your Free Account



By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA. You confirm you are at least 16 years old (13 if you are an authorized Classrooms user).

Loved by learners at thousands of companies

Course Description

As a Data Scientist, the majority of your time should be spent gleaning actionable insights from data -- not waiting for your code to finish running. Writing efficient Python code can help reduce runtime and save computational resources, ultimately freeing you up to do the things you love as a Data Scientist. In this course, you'll learn how to use Python's built-in data structures, functions, and modules to write cleaner, faster, and more efficient code. We'll explore how to time and profile code in order to find 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 the necessary tools to start writing efficient Python code!

  1. 1

    Foundations for efficiencies


    In this chapter, you'll learn what it means to write efficient Python code. You'll explore Python's Standard Library, learn about NumPy arrays, and practice using some of Python's built-in tools. This chapter builds a foundation for the concepts covered ahead.

    Play Chapter Now
    50 xp
    Pop quiz: what is efficient
    50 xp
    A taste of things to come
    100 xp
    Zen of Python
    50 xp
    Building with built-ins
    50 xp
    Built-in practice: range()
    100 xp
    Built-in practice: enumerate()
    100 xp
    Built-in practice: map()
    100 xp
    The power of NumPy arrays
    50 xp
    Practice with NumPy arrays
    100 xp
    Bringing it all together: Festivus!
    100 xp
  2. 2

    Timing and profiling code

    In this chapter, you will learn how to gather and compare runtimes between different coding approaches. You'll practice using the line_profiler and memory_profiler packages to profile your code base and spot bottlenecks. Then, you'll put your learnings to practice by replacing these bottlenecks with efficient Python code.

    Play Chapter Now

In the following tracks

Data EngineerPython ProgrammerPython ProgrammingPython Toolbox


chesterChester IsmaybeccarobinsBecca Robins
Logan Thomas Headshot

Logan Thomas

Scientific Software Technical Trainer, Enthought

Logan is a member of the Technical Training team at Enthought – an organization that provides digital transformation, software consulting, and training services to individuals and companies worldwide. As a Scientific Software Technical Trainer, he focuses on helping students write robust, scalable, and efficient Python code. As a self-proclaimed Python enthusiast, Logan enjoys attending meetups and conferences in the Austin, Texas area to share his knowledge with others.
See More

What do other learners have to say?

I've used other sites—Coursera, Udacity, things like that—but DataCamp's been the one that I've stuck with.

Devon Edwards Joseph
Lloyds Banking Group

DataCamp is the top resource I recommend for learning data science.

Louis Maiden
Harvard Business School

DataCamp is by far my favorite website to learn from.

Ronald Bowers
Decision Science Analytics, USAA