Lesson 3
Problem: Importing Modules¶
Python is a general-purpose programming language and is not specialized for numerical or statistical computation. The core modules that enable Python to store and access data efficiently and that provide statistical algorithms are located in modules. The most important are:
- NumPy (
numpy) - provide the basic array block used throughout numerical Python - pandas (
pandas) - provides DataFrames which are used to store data in an easy-to-use format - SciPy (
scipy) - Basic statistics and random number generators. The most important submodule isscipy.stats - matplotlib (
matplotlib) - graphics. The most important submodule ismatplotlib.pyplot. - statsmodels (
statsmodels) - statistical models such as OLS. The most important submodules arestatsmodels.apiandstatsmodels.tsa.api.
Begin by importing the important modules.
In [ ]:
Problem: Canonical Names¶
Use the as keyword to import the modules using their canonical names:
| Module | Canonical Name |
|---|---|
| numpy | np |
| pandas | pd |
| scipy | sp |
| scipy.stats | stats |
| matplotlib.pyplot | plt |
| statsmodels.api | sm |
| statsmodels.tsa.api | tsa |
Import the core modules using import module as canonical.
In [ ]:
Problem: Importing individual functions¶
- Import
array,sqrt,logandexpfrom NumPy. - Import
OLSfromstatsmodels.regression.linear_model - Import the
statsmodule fromscipy
In [ ]:
In [ ]:
# Setup: A simple 2 by 2 array to use with det
import numpy as np
x = np.array([[2,3],[1,2]])
print(x)
In [ ]:
In [ ]:
In [ ]:
In [ ]: