Scripting

How to Plot the Confidence Interval in Python?

Problem Formulation: How to plot the confidence interval in Python? To plot a filled interval with the width ci and interval boundaries from y-ci to y+ci around function values y, use the plt.fill_between(x, (y-ci), (y+ci), color=’blue’, alpha=0.1) function call on the Matplotlib plt module. The first argument x defines the x values of the filled …

How to Plot the Confidence Interval in Python? Read More »

How to Index Elements in NumPy Arrays?

NumPy is a popular Python library for data science for array, vector, and matrix computations. This puzzle introduces basic indexing of elements in NumPy arrays. Problem Formulation: How to index elements in NumPy arrays? Indexing 1D Arrays with Positive Indices The most simple use of indexing is with the square bracket notation and positive integers: …

How to Index Elements in NumPy Arrays? Read More »

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 »