Python Int to String with Leading Zeros

To convert an integer i to a string with leading zeros so that it consists of 5 characters, use the format string f'{i:05d}’. The d flag in this expression defines that the result is a decimal value. The str(i).zfill(5) accomplishes the same string conversion of an integer with leading zeros. Challenge: Given an integer number. … 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

How to Create a DataFrame in Pandas?

In Python’s pandas module, DataFrames are two-dimensional data objects. You can think of them as tables with rows and columns that contain data. This article provides an overview of the most common ways to instantiate DataFrames. We follow the convention to rename the pandas import to pd. Create a DataFrame From a CSV File Creating … 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

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

Quick Fix: Python throws 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

NumPy Structured Arrays and Record Arrays

Prerequisites Python Fundamentals Numpy basics Learning Outcomes from tutorial How structured data can be formed Numpy Structured Array – Creation, Assigning data and doing operations Creating Structured Datatype (dtype) Memory allocation to Structured Arrays Record Arrays – How it’s related to the Structured Arrays Understanding the requirement of Pandas package Structured arrays are special forms … Read more

Pandas NaN — Working With Missing Data

Pandas is Excel on steroids—the powerful Python library allows you to analyze structured and tabular data with surprising efficiency and ease. Pandas is one of the reasons why master coders reach 100x the efficiency of average coders. In today’s article, you’ll learn how to work with missing data—in particular, how to handle NaN values in … Read more

9 Freelance Developer Books Every Coder Must Read

Freelancing is the new mega trend of our time. Large freelancing platforms such as Upwork and Fiverr grow double-digit—they’re out to disrupt the organization of the world’s talents. And it seems like they’re succeeding! Do you want to participate in this trend rather than only holding on to your cozy developer job as long as … Read more

Python One Line Dictionary

Python’s dictionary data structure is one of the most powerful, most underutilized data structures in Python. Why? Because checking membership is more efficient for dictionaries than for lists, while accessing elements is easier for dictionaries than for sets. In this tutorial, you’ll learn how to perform four common dictionary operations in one line of Python … Read more