DataCamp-Writing-Efficient-Python-Code

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!

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 efficient    50 xp
A taste of things to come    100 xp
Zen of Python    35 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

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.

Examining runtime    50 xp
Using %timeit: your turn!    100 xp
Using %timeit: specifying number of runs and loops    50 xp
Using %timeit: formal name or literal syntax    100 xp
Using cell magic mode (%%timeit)    50 xp
Code profiling for runtime    50 xp
Pop quiz: steps for using %lprun    50 xp
Using %lprun: spot bottlenecks    50 xp
Using %lprun: fix the bottleneck    50 xp
Code profiling for memory usage    50 xp
Pop quiz: steps for using %mprun    50 xp
Using %mprun: Hero BMI    50 xp
Using %mprun: Hero BMI 2.0    50 xp
Bringing it all together: Star Wars profiling    100 xp 

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.

Efficiently combining, counting, and iterating    50 xp
Combining Pokémon names and types    100 xp
Counting Pokémon from a sample    100 xp
Combinations of Pokémon    100 xp
Set theory    50 xp
Comparing Pokédexes    100 xp
Searching for Pokémon    100 xp
Gathering unique Pokémon    100 xp
Eliminating loops    50 xp
Gathering Pokémon without a loop    100 xp
Pokémon totals and averages without a loop    100 xp
Writing better loops    50 xp
One-time calculation loop    100 xp
Holistic conversion loop    100 xp
Bringing it all together: Pokémon z-scores    100 xp 

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.

Intro to pandas DataFrame iteration    50 xp
Iterating with .iterrows()    100 xp
Run differentials with .iterrows()    100 xp
Another iterator method: .itertuples()    50 xp
Iterating with .itertuples()    100 xp
Run differentials with .itertuples()    100 xp
pandas alternative to looping    50 xp
Analyzing baseball stats with .apply()    100 xp
Settle a debate with .apply()    100 xp
Optimal pandas iterating    50 xp
Replacing .iloc with underlying arrays    100 xp
Bringing it all together: Predict win percentage    100 xp
Congratulations!    50 xp