3 Cool Things You Can Do With Python Standard Library

Soner Yıldırım
5 min readDec 22, 2023

Enhance the power of third-party libraries.

Photo by Josh Rakower on Unsplash

Third-party libraries play a crucial role in making Python the predominant choice in data science. From cleaning raw data to building advanced machine learning pipelines, you can find a Python library for simplifying tasks and thus facilitating development processes.

In the midst of this rich selection of libraries, we sometimes overlook the built-in functionalities of Python, which is also known as Python Standard Library.

Python’s built-in functions and methods serve quite well for data-related tasks. We actually use some of them a lot such as len , range , and sorted . In this article, we’ll mention some of the built-in functions and learn about 3 cool things we can do with them.

1. String module for data cleaning

The string module has several functions to do common string operations. I mainly use them for data cleaning.

Textual data can sometimes be really dirty and require lots of cleaning and processing to be useful for downstream processes.

Consider a case where you need to remove punctuations from text. There are different ways of doing it but it’s quite simple with the maketrans method. It returns a translation table, which can be passed to the translate function for executing this translation. Moreover, string.punctuation saves us from having to write all punctuations.

Here is how we do it in code:

import string

sentence = "Hello!!!! Are you planning? to come to the WEDDING?!"

trans = str.maketrans("", "", string.punctuation)

sentence.translate(trans)
# output
'Hello Are you planning to come to the WEDDING'

The variable trans is a translation table that maps each character in string.punctuation to an empty string, which means removing them.

To make it more standardized, we can convert the letters to lowercase.

sentence.translate(trans).lower()
# output
'hello are you planning to come to the wedding'

2. dict constructor

The dict constructor created a dictionary, which is a built-in data structure of Python. A…

--

--