Lab 05 ICT
Lab 05 ICT
LAB – 05
Student Name
Degree/ Syndicate
CMS ID
1
DEPARTMENT OF COMPUTER & SOFTWARE ENGINEERING
COLLEGE OF E&ME, NUST, RAWALPINDI
Lab Objective:
● To familiarize the students with basic programming concepts.
Hardware/Software required:
Hardware: Computer
Software Tool: Online Compiler
Libraries in Python
A library is a collection of precompiled codes that can be used later on in a program for
some specific well-defined operations. Other than pre-compiled codes, a library may contain
documentation, configuration data, message templates, classes, and values, etc.
A Python library is a collection of related modules. It contains bundles of code that can
be used repeatedly in different programs. It makes programming simpler and convenient for the
programmer. As we don’t need to write the same code again and again for different programs.
Python libraries play a very vital role in fields of Machine Learning, Data Science, Data
Visualization, etc.
Use of libraries
As we write extensive programs in Python, we want to maintain the code’s modularity.
For the easy maintenance of the code, we split the code into different parts, and we can use that
code later ever we need it. In Python, modules play that part. Instead of using the same code in
different programs and making the code complex, we define mostly used functions in modules
and we can just simply import them in a program wherever there is a requirement. We don’t need
to write that code but still, we can use its functionality by importing its module. Multiple
interrelated modules are stored in a library. And whenever we need to use a module, we import it
from its library. In Python, it’s a very simple job to do due to its easy syntax. We just need to
use import.
1. NumPy
2
DEPARTMENT OF COMPUTER & SOFTWARE ENGINEERING
COLLEGE OF E&ME, NUST, RAWALPINDI
Example: Sum
arr = np.array([1, 2, 3, 4, 5])
sum_value = np.sum(arr) # Find the sum
print(sum_value)
Some functions
np.random(rows, columns)#to generate array with random values
np.reshape(rows, columns) #to reshape the array
2. Pandas
Pandas is a Python library used for working with data. It has functions for
analyzing, cleaning, exploring, and manipulating data. Pandas allows us to analyze big
data and make conclusions based on statistical theories. Pandas can clean messy data sets
and make them readable and relevant. Relevant data is very important.
Pandas Series
A Pandas Series is like an indexed list. It is used to present a list in tabular form.
Pandas DataFrame
A Pandas DataFrame is a multi-dimensional data structure, like an array, or a
table with rows and columns.
3. MatplotLib
Matplotlib is designed to work with NumPy arrays and pandas data frames. The
library makes it easy to make graphs from tabular data. There are many type of graphs
that can be plotted using this library like line graph, bar graph, scatter plot graph etc.
3
DEPARTMENT OF COMPUTER & SOFTWARE ENGINEERING
COLLEGE OF E&ME, NUST, RAWALPINDI
Lab Tasks:
2. Create a dataframe using pandas and plot a bar graph using matplotlib.