How to Find Min and Max Values in a 1D NumPy Array

Problem Formulation and Solution Overview This article will show you how to find the minimum and maximum values in a 1D NumPy array. To make it more interesting, these examples will generate an array of ten (10) random integers using the random.randint() function from the NumPy library and return the minimum and maximum values of … Read more

How to Remove Text Within Parentheses in a Python String?

Problem Formulation and Solution Overview This article will show you how to remove text within parentheses in Python. To make it more interesting, we have the following running scenario: Rivers Clothing has a CSV file containing all their employees. The format is currently first name (middle name) and last name (for example, Martin (Robert) Simpson). … Read more

How to Clean and Format Phone Numbers in Python

Problem Formulation and Solution Overview This article will show you how to create, clean up, and format phone numbers in Python. To make it more interesting, we have the following scenario. Right-On Realtors has a Contact Us form on their main website containing several fields. One of these fields is a Phone Number. Upon submission, … Read more

How to Generate a Random Date Between Two Dates in Python?

Problem Formulation and Solution Overview This article will show you how to generate a random date between two dates in Python. πŸ’¬ Question: How would we write code to generate a random date between two dates? We can accomplish this task by one of the following options: Method 1: Use datetime.timedelta() and random.random() Method 2: … Read more

How to Subtract Two Python Lists (Element-Wise)?

Problem Formulation and Solution Overview This article will show you how to subtract two Lists in Python. πŸ’‘ Note: Before subtracting these Lists, ensure each List is of the same length and contains subtractable data. For example, subtracting a List of strings from a List of integers or floats will result in an error. Whereas … Read more

How to Determine Script Execution Time in Python?

Problem Formulation and Solution Overview This article will show you how Python can determine a script’s execution time. Let’s say you have written several code sections. Each section performs identical tasks. How could you best determine which section works faster and more efficiently? πŸ’¬ Question: How would we write code to determine a script’s execution … Read more

How to Retrieve a Single Element from a Python Generator

This article will show you how to retrieve a single generator element in Python. Before moving forward, let’s review what a generator does. Quick Recap Generators πŸ’‘ Definition Generator: A generator is commonly used when processing vast amounts of data. This function uses minimal memory and produces results in less time than a standard function. … Read more

How to Change Tuple Values in Python?

Problem Formulation and Solution Overview This article will show you how to change tuple values in Python. To make it more interesting, we have the following running scenario: Eddie, the Meteorologist at NTCV, has calculated an incorrect five (5) Day weather forecast. These values are saved as a Tuple and require updating. πŸ’¬ Question: How … Read more