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.

Python JSON: Read and Modify a File

Python Read JSON File and Modify

Changing a stored setting may mean reading its JSON file in Python. Python’s json module reads that file into Python values that a script can edit and save as JSON. I’ll explain how Python represents JSON data, then show how…

Python PIP – Package Manager

Python PIP - Package Manager

When a Python project needs a library, the first task is finding a package that fits what the code needs. pip installs Python packages from PyPI or another configured package index. This article shows how to search PyPI by purpose…

The pickle Module in Python

The pickle Module in Python

A value created in one Python run may still be useful after that run ends. Python’s pickle module turns an object into bytes that Python can reconstruct. I’ll show how to save and restore a Python value with pickle, then…

Pandas qcut: An Explanation with Examples

Pandas qcut: An Explanation with Examples

Splitting a set of numbers, such as test scores, into groups like quartiles lets you compare values by where they rank. pandas qcut does this by rank, putting a similar number of values in each group. This guide shows how…

NumPy empty and empty_like

NumPy empty and empty_like

When you’re about to fill a NumPy array with your own values straight away, you only need NumPy to set aside the space. np.empty creates that array without setting its values, and np.empty_like does the same using another array’s shape…

Use np.arctan2() for Coordinate Angles

Use np.arctan2() for Coordinate Angles

Given a point’s x and y coordinates, you may need the angle it makes with the x-axis. np.arctan2 calculates that angle and uses the signs of both coordinates to put it in the right quadrant. You’ll get the angle in…

SciPy Minimize: Fit a Function and Check the Result

SciPy Minimize: Fit a Function and Check the Result

Fitting a line to data points means finding the slope and intercept that make the line’s errors as small as possible. SciPy’s minimize function searches for those values, starting from a guess you give it. The example writes the error…