Python has become a go-to language for many first-time programming learners. Many others with a different language background may consider switching to Python given its extensive capabilities in machine learning, data processing, and other domains.
Python is designed to be very straightforward. However, there are some scenarios that beginners may find confusing. In this article, I’d like to clarify some confusing Python features.
When we construct the
if…else… statement, we need to send conditions for evaluation. When the condition evaluates to
if block executes. When it’s
else block executes.
If the condition has several pieces, we…
At its core, Python is an object-oriented programming (OOP) language. Implementation-wise, Python organizes its building blocks, such as packages, modules, classes, functions, and data, as different kinds of objects. Thus, understanding the characteristics of objects is essential to writing better Python code with fewer bugs.
In this article, I’d like to focus on one specific characteristic of Python objects: callability. Going beyond the basic concept, I’d like to discuss its practical implications that you can actually use in your Python projects.
Callability refers to whether an object can be called. Like in most other modern languages, calling an object is…
Web applications are one of the most convenient ways to showcase your data science work. Building web applications can be daunting to many data scientists if they don’t have any web development experience. However, with the streamlit framework, web applications are no longer difficult for data scientists — if you know Python, you can build interactive web apps with streamlit — this awesome framework does the hard lift to make and layout web elements for us under the hood. We’ll simply focus on the data part.
To install the streamlit framework, use the pip tool.
pip install streamlit
One important goal of any programming project pertains to its maintainability. No matter the size of the project, you always want to have a maintainable code base so that you don’t waste your or your teammates’ time when it comes to the maintenance phase of the project in the long term. Thus, when we work on our project, we have to keep maintainability in mind.
One essential way to improve the project’s maintainability is to write concise code — for a couple of reasons. First, generally speaking, concise code is more readable and easier for your teammates to understand. …
There is no need to justify the importance of the pandas library in the world of data science. If you use Python, this library is the go-to tool for any data processing jobs. One versatile functionality of the pandas library is built upon the
groupby function, which creates a
GroupBy object that supports lots of possible operations.
groupby-related functionality is so powerful, such that it’s so hard for many of us to remember all of its features. Moreover, another notable side effect of the versatility is that beginners may find themselves lost in how to use the
One well-known Python trick is to show the Zen of Python in your Python console. In the Zen of Python, author Tim Peters created a collection of 19 guiding principles for writing Python programs. The second principle is “Explicit is better than implicit,” which means that when we write Python code, it should be explicit enough to tell what it does without much verbal explanation.
However, the actual implementation of many Python features involves implicit operations under the hood. In this article, I’d like to review five such features.
In Python classes, we declare instance methods that can be invoked…
Functions constitute the driving force in any Python or programming project. In addition to its data models and structural design, a project’s functions play essential roles in its maintainability. We often talk about the readability of functions and other components in the code base. In many contexts, the readability of functions refers to sensible names and clear docstrings. These should be the priority for writing better functions.
Beyond these fundamentals, there are optional features in Python that can make your functions even better. They’re friendlier for end-users. In this article, I’d like to talk about four of these features.
Virtual environments are not the most straightforward concept to Python beginners. When we install software, such as Microsoft Office and Evernote, most of us are used to applying the default configurations, which include the installation of the software for all users on your computer. In other words, the software is installed at the system level such that only one copy of the software is shared among different users.
It’s a habit for most of us that we have built for years. We took this habit when we started to learn Python. We installed Python on the computer and learned to…
Programming has gradually become a critical skill in many professions. With its growing popularity, more people are riding the wave and surging into the world of ones and zeroes. A significant portion of them don’t have any systematic training in programming — they pick up just enough to get their jobs done. Certainly, some people who are motivated self-learners can make a dramatic improvement over the years, but others stay at a mediocre level.
We should respect those in the former group, whom I’d like to refer to as professional programmers, because they take responsibility for their whole work —…
The Jupyter Notebook is a very handy coding tool for data scientists. It allows us to visualize data in the form of text and images while we’re moving forward with the processing and analysis of our datasets. After learning the basic operations with Notebook, we may want to try something more useful that can help improve our Notebook experience and work productivity. In this article, I’d like to share some features that address some particular needs in our data science work.
To run commands in cells, we can simply prefix an exclamation mark before the command.