How Does Pandas Concat Work?

The pandas.concat( ) function combines the data from multiple Series and/or DataFrames fast and in an intuitive manner. It is one of the most basic data wrangling operations used in Pandas. In general, we draw some conclusions from the data by analyzing it. The confidence in our conclusions increases as we include more variables or … Read more

Python Math Domain Error (How to Fix This Stupid Bug)

You may encounter a special ValueError when working with Python’s math module. Python raises this error when you try to do something that is not mathematically possible or mathematically defined. To understand this error, have a look at the definition of the domain: “The domain of a function is the complete set of possible values … Read more

Minimum Viable Product (MVP) in Software Development — Why Stealth Sucks

This chapter from my upcoming book “The Art of Clean Code” (NoStarch 2022) teaches you a well-known but still undervalued idea. The idea is to build a minimum viable product (in short: MVP) to test and validate your hypotheses quickly without losing a lot of time in implementation. In particular, you’ll learn how to apply … Read more

np.polyfit() — Curve Fitting with NumPy Polyfit

The np.polyfit() function, accepts three different input values: x, y and the polynomial degree. Arguments x and y correspond to the values of the data points that we want to fit, on the x and y axes, respectively. The third parameter specifies the degree of our polynomial function. For example, to obtain a linear fit, … Read more

How to Calculate the Column Variance of a DataFrame in Python Pandas?

Want to calculate the variance of a column in your Pandas DataFrame? In case you’ve attended your last statistics course a few years ago, let’s quickly recap the definition of variance: it’s the average squared deviation of the list elements from the average value. You can calculate the variance of a Pandas DataFrame by using … Read more

Python Function Call Inside List Comprehension

Question: Is it possible to call a function inside a list comprehension statement? Background: List comprehension is a compact way of creating lists. The simple formula is [expression + context]. Expression: What to do with each list element? Context: What elements to select? The context consists of an arbitrary number of for and if statements. … Read more

Python TypeError: Object is Not Subscriptable (How to Fix This Stupid Bug)

Do you encounter this stupid error? You’re not alone—thousands of coders like you generate this error in thousands of projects every single month. This short tutorial will show you exactly why this error occurs, how to fix it, and how to never make the same mistake again. So, let’s get started! Python throws the TypeError … Read more

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

The most Pythonic way to convert a list of floats fs to a list of integers is to use the one-liner fs = [int(x) for x in fs]. It iterates over all elements in the list fs using list comprehension and converts each list element x to an integer value using the int(x) constructor. This … Read more

How to Generate Text Automatically With Python? A Guide to the DeepAI API

Do you want to enrich your Python script with powerful text-generation capabilities? You’re in the right place! What does it do? I just discovered DeepAI’s API that automatically generates a body of text, given a sentence fragment or topic keyword. How can it be used? You can use this as a basis to generate text … Read more

10 Minutes to Pandas (in 5 Minutes)

This tutorial provides you a quick and dirty introduction to the most important Pandas features. A popular quickstart to the Pandas library is provided by the official “10 Minutes to Pandas” guide. This tutorial in front of you aims to cover the most important 80% of the official guide, but in 50% of the time. … Read more