Python Libraries


Python has several advanced features that extend, enhance and reuse parts of the code. To access these features, you can import them from libraries, packages, and modules. These features are not included in basic Python, so it’s necessary to add them to your scripts. The terms library and package are often used interchangeably.

Libraries and packages provide sets of modules that are essential for data professionals. Modules are accessed from within a package or a library. Modules are Python files that contain collections of functions and global variables. Global variables differ from other variables because these variables can be accessed from anywhere in a program or script. Modules are used to organize functions, classes, and other data in a structured way.

A library, or “package”, broadly refers to a reusable collection of code. Again, it also contains related modules and documentation. Some examples are NumPy, pandas, matplotlib and seaborn.

There are several conventions that the Python community had adopted when they are creating aliases for libraries imported. It is recommended to use them. The alias for pandas is pd.

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
import statsmodels as sm

The Pandas standard library comes with a number of built-in modules such as math, datertime and random. As long as you have Python installed you can import these directly. For example, you could write import math. Then you could use it to calculate a factorial for example like this math.factorial(4)

Leave a Reply