Build your ultimate AI agent
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!The videos contain live transcripts you can reveal by clicking "Show transcript" at the bottom left of the videos.
The course glossary can be found on the right in the resources section.
To obtain CPE credits you need to complete the course and reach a score of 70% on the qualified assessment. You can navigate to the assessment by clicking on the CPE credits callout on the right.
Feels like what you want to learn?
Start Course for FreeWhat you'll learn
- Assess when and how to replace explicit loops with vectorized NumPy array or pandas DataFrame operations for faster computation
- Differentiate between pandas row-iteration methods (iloc, iterrows, itertuples, apply) to select the most performant approach for a given task
- Evaluate code execution time and memory usage by applying %timeit, line_profiler, and memory_profiler outputs
- Identify built-in Python functions, data structures, and modules that provide efficient alternatives to manual implementations
- Recognize scenarios where combinatoric generators, Counter objects, and set operations reduce runtime relative to traditional looping constructs
Prerequisites
Curriculum
Course outline
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.
- Welcome!50 XP
- Pop quiz: what is efficient50 XP
- A taste of things to come100 XP
- Zen of Python50 XP
- Building with built-ins50 XP
- Built-in practice: range()100 XP
- Built-in practice: enumerate()100 XP
- Built-in practice: map()100 XP
- The power of NumPy arrays50 XP
- Practice with NumPy arrays100 XP
- Bringing it all together: Festivus!100 XP
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.
3
Gaining efficiencies
This chapter covers more complex efficiency tips and tricks. You'll learn a few useful built-in modules for writing efficient code and practice using set theory. You'll then learn about looping patterns in Python and how to make them more efficient.
4
Basic pandas optimizations
This chapter offers a brief introduction on how to efficiently work with pandas DataFrames. You'll learn the various options you have for iterating over a DataFrame. Then, you'll learn how to efficiently apply functions to data stored in a DataFrame.
Writing Efficient Python Code
Course
Complete

