Scripting

How to Calculate Percentiles in Python

This article deals with calculating percentiles. Percentiles are statistical indicators that are used to describe specific portions of a sample population. The following sections will explain what percentiles are, what they are used for and how to calculate them, using Python. As you will see, Python allows solving this problem in multiple ways, either by …

How to Calculate Percentiles in Python Read More »

How to Print an Integer with Commas as Thousands Separators in Python?

Problem Formulation: Given an integer number. How to convert the integer to a string representation for printing or other use that has thousand separators? Example: Given an integer number 1000000. You want the string representation ‘1,000,000’. Method 1: f-Strings Using the modern f-strings is, in my opinion, the most Pythonic solution to add commas as …

How to Print an Integer with Commas as Thousands Separators in Python? Read More »

Python format() Function: No-BS Guide by Example

The web is filled with shitty tutorials about Python’s formatting feature. At times, it can become really confusing—and it’s hard to see the forest for the trees. In this tutorial, I’ll try to gradually build a basic understanding of the built-in format() function, what it does, and how you can use it to become a …

Python format() Function: No-BS Guide by Example Read More »

Python float() Function

Python’s built-in float(value) function converts the argument value to a float number. For example, float(’42’) converts the string value ’42’ into the float number 42.0. Argument value A Python object to be converted into a float number. The value object must have an __float__() method that returns the associated float number—otherwise a ValueError will be …

Python float() Function Read More »

Python int() Function

Python’s built-in int(value) function converts the argument value to an integer number. For example, int(’42’) converts the string value ’42’ into the integer number 42. The int() function on a float argument rounds down to the closest integer. Argument value A Python object to be converted into an integer number. The value object must have …

Python int() Function Read More »

How to Remove Everything After the Last Character in a String?

Problem Formulation Given string s, and character c. How to remove all characters in s after the first occurrence of c? Example Given: – string s = ‘hello world’, and – empty space character c = ‘ ‘. Desired result: ‘hello’ Method 1: string.index() + slicing To remove everything after the first occurrence of character …

How to Remove Everything After the Last Character in a String? Read More »

EZGmail and Python — Managing Your Emails Programmatically

Hey Finxters! Among the many daily tasks you can achieve with Python, there is one Siri-like task that comes quite handy: managing your emails in a programmatic way.  Of course, many emails need your human understanding to be processed properly, and this article is not about implementing a neural network to fine-tune every single email …

EZGmail and Python — Managing Your Emails Programmatically Read More »