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 … Read more

Python frozenset() — A Simple Guide with Video

Python’s built-in frozenset() function creates and returns a new frozenset object. A frozenset is an immutable set—so you cannot change the frozenset after creation and set methods such as add() or remove() don’t work on the frozenset. Without an argument, frozenset() returns an empty frozenset. With the optional argument, frozenset(iter) initializes the new frozenset with … 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 … Read more

Python set() Function — A Simple Guide with Video

Python’s built-in set() function creates and returns a new set object. A set is an unordered collection of unique elements. Without an argument, set() returns an empty set. With the optional argument, set(iter) initializes the new set with the elements in the iterable. Read more about sets in our full tutorial about Python Sets. Usage … Read more

Logistic Regression Scikit-learn vs Statsmodels

What’s the difference between Statsmodels and Scikit-learn? Both have ordinary least squares and logistic regression, so it seems like Python is giving us two ways to do the same thing. Statsmodels offers modeling from the perspective of statistics. Scikit-learn offers some of the same models from the perspective of machine learning. So we need to … Read more