Sitelet https://www.askpython.com/python-modules

Category Python Modules

Modules is one of the best feature of Python. Except some core modules, you can install what you need and keep your Python setup smooth.

np.linalg.solve() Linear Systems

np.linalg.solve() Linear Systems

To solve a set of linear equations, find the values of its unknowns. NumPy’s np.linalg.solve() does that when the coefficient matrix has the same number of rows and columns and its equations are independent. I’ll show how to put the…

Statsmodels Library Structure and Imports

Statsmodels Library Structure and Imports

Finding an import in Statsmodels starts with the model or helper you want to use. The package groups models, tests and tools into subpackages by subject, while an API module collects selected objects for convenient use. I’ll show how to…

Python Logarithm Base 2 Using NumPy log2()

Python Logarithm Base 2 Using NumPy log2()

For a set of numbers, you can use a base-2 logarithm to express each value as an exponent on two. NumPy’s log2 function calculates that result element by element for array-like input. This article shows how to apply np.log2 to…

Pandas Get Dummies: Encode Categories

Pandas Get Dummies: Encode Categories

Turning category labels into indicator columns gives a pandas table one column for each category. pandas.get_dummies() creates those columns, using Boolean values by default or integers when you set dtype=int. I’ll show how to encode selected columns and align training…

Regression in Python: Fit Models with NumPy

Regression in Python: Fit Models with NumPy

To estimate a numeric target from input values, regression gives you a way to model how those values relate to the target. NumPy’s least-squares routine finds coefficients from arrays, with each coefficient describing how an input value changes the prediction.…

SVD NumPy: Decompose a Matrix

SVD NumPy: Decompose a Matrix

To decompose a matrix in NumPy, use SVD. SVD expresses the matrix as a product of factors. I’ll explain the shapes of those factors and show how to reconstruct the matrix or make a lower-rank approximation. TL;DR: NumPy SVD returns…

Queue in Python: Create and Use Queues

Queue in Python: Create and Use Queues

As you build a Python program that processes items in sequence, a queue holds them until they are retrieved. Python’s queue module includes synchronized FIFO queues, while collections.deque provides a basic FIFO container. I’ll explain how to create a queue…

Pandas Melt and Pivot Data

Pandas Melt and Pivot Data

A table can keep one row per record while storing each measurement in a separate column. Pandas melt turns selected measurement columns into labeled rows, and pivot reshapes those rows into columns again. This article walks through choosing columns for…

Python pytz: Migrate to zoneinfo

Python pytz: Migrate to zoneinfo

Updating timezone code in a Python app means checking that its dates still mean what you intend. pytz is a separately installed package for working with time zones, while zoneinfo is Python’s built-in option in Python 3.9 and later. This…