Professional Documents
Culture Documents
Libraries or Modules
Libraries are pre defined code
Using libraries we can use the functions or method which are not in build
We use modules to break down large programs into small manageable and organized files.
Furthermore, modules provide reusability of code.
In [2]:
# Example of Libraries
import math
import time
In [ ]:
math.sqrt
In [2]:
math.sqrt(36)
Out[2]: 6.0
In [3]:
math.pi
Out[3]: 3.141592653589793
In [3]:
pi
---------------------------------------------------------------------------
<ipython-input-3-f84ab820532c> in <module>
----> 1 pi
Syntax
import moduleName or
import PackageName
In [6]:
import math
math.pi
Out[6]: 3.141592653589793
In [ ]:
file:///C:/Users/rgandyala/Downloads/9.a. Libraries and Modules.html 1/5
1/16/22, 7:46 AM 9.a. Libraries and Modules
In [4]:
import time
In [6]:
time.tzname
In [7]:
time.time()
# time is library
# time is function
Out[7]: 1637123333.666412
In [5]:
print("sleep for ten seconds")
print("wake up")
wake up
In [3]:
import math
In [4]:
math.pi
Out[4]: 3.141592653589793
In [4]:
import datetime
x = datetime.datetime.now()
print(x)
2021-11-17 20:35:23.711246
In [5]:
import datetime
x = datetime.datetime.now()
print(x.year)
2021
In [6]:
import datetime
x = datetime.datetime(2020, 5, 17)
## yy mmm dd - ymd
print(x)
2020-05-17 00:00:00
In [9]:
import math
In [31]:
#min() and max() are inbuild function to find the min and max value
In [8]:
import math
x = math.sqrt(64)
print(x)
8.0
In [11]:
import math
x = math.ceil(1.4)
y = math.floor(1.4)
print(x) # returns 2
print(y) # returns 1
In [7]:
import math
In [10]:
math.sqrt(36)
Out[10]: 6.0
you can create an alias when you import a module, by using the as keyword:
In [12]:
import pandas
In [ ]:
# pandas.read_CSV(" Path ")
In [10]:
import numpy as np
In [11]:
import pandas as pd
#pd.read_CSV("path")
In [13]:
import sklearn.preprocessing
In [14]: sklearn.preprocessing.binarize
In [11]:
import sklearn.preprocessing as sp
In [17]:
Syntax
import packagename.libraryname
In [20]:
# without using Alias Keyword
In [21]:
from sklearn.preprocessing import binarize
In [22]:
# If we user * we will import all function in that module
In [23]:
from time import *
In [24]:
import pytroch
import keras
---------------------------------------------------------------------------
<ipython-input-24-ddab4d34effa> in <module>
In [25]:
# we dont have module here in pytroch so we have to install that module in pythin
PIP
PIP is a package manager for Python packages, or modules
syntax
Open the command prompt ( anaconda prompt ) then run this code to install the module
In [9]:
import sklearn
In [10]:
from sklearn.preprocessing import scale
In [ ]: