0% found this document useful (0 votes)
12 views4 pages

Lab 05 ICT

Uploaded by

abdulmoeez70899
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

Lab 05 ICT

Uploaded by

abdulmoeez70899
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

DEPARTMENT OF COMPUTER & SOFTWARE ENGINEERING

COLLEGE OF E&ME, NUST, RAWALPINDI

CS-117 Applications of ICT

LAB – 05

Course Instructor: Asst. Prof. Jahan Zeb

Lab Instructor: Engr. Ayesha Khanam

Student Name

Degree/ Syndicate

CMS ID

1
DEPARTMENT OF COMPUTER & SOFTWARE ENGINEERING
COLLEGE OF E&ME, NUST, RAWALPINDI

LAB # 5: INTRODUCTION TO PROGRAMMING (PYTHON LIBRARIES)

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.

Syntax: import [name of library]


name of library . requiredFunction #access the functions of library using dot ( . ) operator in our code.

Example: import math


A = 16
print(math.sqrt(A))

Following are some basic python libraries:

1. NumPy

2
DEPARTMENT OF COMPUTER & SOFTWARE ENGINEERING
COLLEGE OF E&ME, NUST, RAWALPINDI

NumPy is a general-purpose array-processing library. It is the fundamental library


for scientific computing with Python. NumPy’s main object is the multidimensional
array. It is a table of elements (usually numbers), all of the same type, indexed by
positive integers. In NumPy, dimensions are called axes. The number of axes is rank.
NumPy’s array class is called ndarray. It is also known by the alias array.

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.

Example: import pandas as pd


arr = [5, 9, 3]
myvar = pd.Series(arr)
print(myvar)

Pandas DataFrame
A Pandas DataFrame is a multi-dimensional data structure, like an array, or a
table with rows and columns.

Example: import pandas as pd


data = {
"calories": [420, 380, 390],
"duration": [50, 40, 45]
}
df = pd.DataFrame(data) #load data into a DataFrame object
print(df)

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

Some Functions: plt.bar( ) plt.show( ) plt.title( ) plt.xlable( )

To plot bar graph: plt.bar(df[x-axis], df[y-axis], color=[ ])

Lab Tasks:

1. Create and Manipulate Arrays using numpy.

i. Create a 1D NumPy array with 4 values.


ii. Reshape the array into a 2D array with 3 rows and 6 columns.
iii. Print the shape of the reshaped array.
iv. Print the element in the last row, last column.

2. Create a dataframe using pandas and plot a bar graph using matplotlib.

i. Create a DataFrame containing the following data:


Name: [ ]
Age: [ ]
City: [ ]

ii. Print the DataFrame.


iii. Add a new column called “Salary” with different values [ ].
iv. Print the updated DataFrame.
v. Plot the bar graph using matplotlib:
X axis: Names
Y axis: Salary

You might also like