Writing Efficient Python Code
Learn to write efficient code that executes quickly and allocates resources skillfully to avoid unnecessary overhead.
Commencer Le Cours Gratuitement4 heures15 vidéos52 exercices124 988 apprenantsDéclaration de réalisation
Créez votre compte gratuit
ou
En continuant, vous acceptez nos Conditions d'utilisation, notre Politique de confidentialité et le fait que vos données sont stockées aux États-Unis.Formation de 2 personnes ou plus ?
Essayer DataCamp for BusinessApprécié par les apprenants de milliers d'entreprises
Description du cours
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!
Formation de 2 personnes ou plus ?
Donnez à votre équipe l’accès à la plateforme DataCamp complète, y compris toutes les fonctionnalités.Dans les titres suivants
Programmation Python
Aller à la piste- 1
Foundations for efficiencies
GratuitIn 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 xpPop quiz: what is efficient50 xpA taste of things to come100 xpZen of Python50 xpBuilding with built-ins50 xpBuilt-in practice: range()100 xpBuilt-in practice: enumerate()100 xpBuilt-in practice: map()100 xpThe power of NumPy arrays50 xpPractice with NumPy arrays100 xpBringing 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.
Examining runtime50 xpUsing %timeit: your turn!100 xpUsing %timeit: specifying number of runs and loops50 xpUsing %timeit: formal name or literal syntax100 xpCode profiling for runtime50 xpPop quiz: steps for using %lprun50 xpUsing %lprun: spot bottlenecks50 xpUsing %lprun: fix the bottleneck50 xpCode profiling for memory usage50 xpPop quiz: steps for using %mprun50 xpUsing %mprun: Hero BMI50 xpUsing %mprun: Hero BMI 2.050 xpBringing it all together: Star Wars profiling100 xp - 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.
Efficiently combining, counting, and iterating50 xpCombining Pokémon names and types100 xpCounting Pokémon from a sample100 xpCombinations of Pokémon100 xpSet theory50 xpComparing Pokédexes100 xpSearching for Pokémon100 xpGathering unique Pokémon100 xpEliminating loops50 xpGathering Pokémon without a loop100 xpPokémon totals and averages without a loop100 xpWriting better loops50 xpOne-time calculation loop100 xpHolistic conversion loop100 xpBringing it all together: Pokémon z-scores100 xp - 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.
Intro to pandas DataFrame iteration50 xpIterating with .iterrows()100 xpRun differentials with .iterrows()100 xpAnother iterator method: .itertuples()50 xpIterating with .itertuples()100 xpRun differentials with .itertuples()100 xppandas alternative to looping50 xpAnalyzing baseball stats with .apply()100 xpSettle a debate with .apply()100 xpOptimal pandas iterating50 xpReplacing .iloc with underlying arrays100 xpBringing it all together: Predict win percentage100 xpCongratulations!50 xp
Formation de 2 personnes ou plus ?
Donnez à votre équipe l’accès à la plateforme DataCamp complète, y compris toutes les fonctionnalités.Dans les titres suivants
Programmation Python
Aller à la pisteLogan Thomas
Voir PlusScientific Software Technical Trainer, Enthought
Qu’est-ce que les autres apprenants ont à dire ?
Inscrivez-vous 15 millions d’apprenants et commencer Writing Efficient Python Code Aujourd’hui!
Créez votre compte gratuit
ou
En continuant, vous acceptez nos Conditions d'utilisation, notre Politique de confidentialité et le fait que vos données sont stockées aux États-Unis.