filmov
tv
Python Tutorial : Writing Efficient Python Code
Показать описание
---
Hello and welcome! My name is Logan Thomas, and I'll be your guide through this course about writing efficient code using Python.
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.
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.
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, but it also 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!
In the previous slide, I discussed the importance of following Python's guiding principles and idioms. But what are these idioms you may ask? Enter The Zen of Python.
This is a list of a few idioms and best practices that summarize Python's design philosophy. Take a moment to familiarize yourself with these principles. Chances are, if you have been working with Python for some time, you are already familiar with most of them. If not, don't worry! We'll be touching on a few of these concepts throughout the course.
Before moving on, we should check your Python knowledge level.
There are a few things this course assumes you have a working knowledge of. You don't need to be an expert on the topics listed here, but you should definitely be familiar with them in order to get the most out of this course.
Now that we've defined efficient and Pythonic code, and touched on a few things you should already be familiar with, it's time to start coding!
#DataCamp #PythonTutorial #WritingEfficientPythonCode