How to Import Libraries to Python

with No Comments

What are Libraries 

  • Libraries are packages of codes that are developed by others which allow users to easily perform actions.
  • If we have to write the codes on our own, it will take us so much time to do it, plus, we will have to understand the mechanism of actions all the way from inside out.
  • You should always try to find and import the right libraries, it will save you tons of time.
  • Say you are stuck on writing the codes or find it time consuming, you shall look for libraries on the internet. Someone might have written something similar before and you might want to import their libraries.
  • Here is link to the Standard Library from Python 

Python Libraries for Machine Learning, Deep Learning, Artificial Intelligent

  • numpy & scipy : scientific calculation
  • pandas : data handling / import
  • matplotlib : creating graph
  • math
  • scikit learn  (sklearn) : statistic and data science
  • theano : Deep Learning & Artificial Intelligent
  • tensorflow :Deep Learning & Artificial Intelligent
  • keras : Combination of theano and tensorflow

Pip Install

Before the library is imported to the Python, we need to install them first.

1.) In Anaconda Python (Spyder), Go to Tools > Open a Terminal

how to install libraries in python - pip install

 

2.) In the BOTTOM RIGHT pane, find the tab “Python Console” and you should see “Terminal” is opened
how to install libraries in python - terminal
Select “Python Console” instead, the BOTTOM RIGHT pane became the “Terminal” where users can install the python libraries

 

3.) Enter “pip list” in the terminal , and you should see a list of libraries you have installed

how to install libraries in python - pip list

 

4.) Install the library

For example :

pip install numpy

 

pip install scipy

 

pip install matplotlib

 

pip install scikit-learn

 

pip install theano

 

pip install tensorflow

 

pip install keras


How to Import Libraries in Python

Type in Editor Section

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

Select them and hit Ctrl + Enter

import python libraries

When the library is imported, you should see the codes executed in iPython Console on the BOTTOM RIGHT pane.

import python libraries - imported


 How to Update all lib

if you are using Anaconda, then you can use the following.

conda update –all

it will then ask users

Proceed ([y]/n)?

Hit Y and enter to continue.

Other Sections on Data Handling in Python

1.) How to Import Libraries 

2.) How to Know and Change the Working Directory 

3.) How to Import CSV Data using Pandas

4.) How to Set Dependent Variables and Independent Variables using iloc

5.) How to Handle Missing data with Imputer

6.) How to Set Categorical Data (Dummy Variable) using LabelEncoder and OneHotEncoder

7.) How to Split Data into Training Set and Testing Set

8.) How to Apply Feature Scaling

Leave a Reply