Pandas DataFrame add_prefix() Method

Preparation Before any data manipulation can occur, two (2) new libraries will require installation. The Pandas library enables access to/from a DataFrame. The NumPy library supports multi-dimensional arrays and matrices in addition to a collection of mathematical functions. To install these libraries, navigate to an IDE terminal. At the command prompt ($), execute the code … Read more

pd.DataFrame.groupby() – A Simple Illustrated Guide

In Python, the pandas.DataFrame.groupby() function splits a pandas.DataFrame into subgroups. It is a part of a full groupby operation, where we usually split the data, apply a function, and then combine the result. Here is the argument table of pandas.DataFrame.groupby(). If it sounds great to you, please continue reading, and you will fully understand the … Read more

How to Fix ImportError: No module named pandas [Mac/Linux/Windows/PyCharm]

Quick Fix: Python raises the ImportError: No module named pandas when it cannot find the Pandas installation. The most frequent source of this error is that you haven’t installed Pandas explicitly with pip install pandas. Alternatively, you may have different Python versions on your computer, and Pandas is not installed for the particular version you’re … Read more

How to Find Common Elements of Two Lists in Python

Problem Formulation and Solution Overview In this article, you’ll learn how to locate and return the common elements of two (2) lists in Python. To make it more fun, we have the following running scenario: Bondi Brokers offers two (2) Marketable Bonds: 3-years and 5-years. Each yields different amounts. To determine which Bond best suits … Read more

How to Use Pandas Rolling – A Simple Illustrated Guide

This article will demonstrate how to use a pandas dataframe method called rolling(). What does the pandas.DataFrame.rolling() method do? In short, it performs rolling windows calculations. It is often used when working with time-series data or signal processing. I will shortly dive into a few practical examples to clarify what this means in practice. The … Read more

How to Convert an Integer List to a String List in Python

The most Pythonic way to convert a list of integers ints to a list of strings is to use the one-liner strings = [str(x) for x in ints]. It iterates over all elements in the list ints using list comprehension and converts each list element x to a string using the str(x) constructor. This article … Read more

How to Apply a Function to Series Elements

Problem Formulation and Solution Overview As a Python Coder, situations arise where you will need to apply a function against elements of a Series. To make it more fun, we have the following running scenario: Rivers Clothing does business with six (6) different countries. The Tax Rates for the associated countries have increased by 2%. … Read more