You are on page 1of 11

University Institute of Engineering

Department of Computer Science & Engineering

Experiment: 1.1

Student Name: UID:


Branch: Computer Science & Engineering Section/Group
Semester:1 Date of Performance: 6.09.2022
Subject Name:
Subject Code:

1. Aim of the practical:


Explore data pre-processing packages and AIML algorithms.

2. Tool Used:

Google Colaboratory

3. Basic Concept/ Command Description:


It is basically a free notebook environment that runs entirely in the cloud.It helps to edit documents similar to google
docs. Colab supports many popular and high-level machine learning libraries which can be easily loaded
in notebook.

 Write and execute Python code without having a local setup.


 Interactive tutorials to learn machine learning and neural networks.
 Create new notebooks.
 Upload the existing notebooks.
  Import data from Google Drive.
  Save notebooks from/to Google Drive.
  Import/Publish notebooks from GitHub.
 Import datasets from external sources such as Kaggle.
   Integrate PyTorch, TensorFlow, Keras, OpenCV.
  Free Cloud service with free GPU and TPU.
 
University Institute of Engineering
Department of Computer Science & Engineering

4. Code:
a) file handling

try:
    fp = open('abc.txt')    # Open the file in reading mode
    for line in fp:         # Print line by line
        print (line)
    fp.close()              # Close the file

except:
    print("Error!! No such file exist")

try:
    with open('abc.txt', 'r') as f:
        line  = f.read()
        print (line)

except:
    print("Error!! No such file exist")

fp = open('textdata.txt','w')      # Open the file in writing mode

for i in range(1,11):
    fp.write(str(i) + "\n")      # Writing to the file line by line
fp.close()

print ("Writing done !! \nOpen result.txt to view the content")

b)data manipulation
import pandas as pd

a1 = [1, 3, 5, 7, 9, 2, 4, 6, 8]
a2 = pd.Series(a1)

print(a2)

import pandas as pd

a1 = [1, 3, 5, 7, 9, 2, 4, 6, 8]
University Institute of Engineering
Department of Computer Science & Engineering

a2 = ['a','b','c','d','e','f','g','h','i']
a3 = pd.Series(a1, a2)
#a3 = pd.Series(a2, a1)
print(a3

import pandas as pd

d1 = {'Oranges':3, 'Apples':4, 'Mangoes':2, 'Banana':12}
d2 = pd.Series(d1)

print (d2)
print (type(d2))

import pandas as pd

a1 = [[1,3,5],[2,4,6]]
a2 = pd.Series(a1)

print (a2)

c)data visualization

Line Plot
x = [0, 1, 2, 3, 4, 5, 6]
y = [i **2 for i in x ]
plt.plot(x, y)
plt.show()

Multiple line plot


x  = [1, 2, 3, 4, 5]

y1 = [50, 40, 70, 80, 20]

y2 = [80, 20, 20, 50, 60]

y3 = [70, 20, 60, 40, 60]
University Institute of Engineering
Department of Computer Science & Engineering

y4 = [80, 20, 20, 50, 60]

plt.plot(x, y1, 'g', label='Enfield', linewidth=2)

plt.plot(x, y2, 'c', label='Honda', linewidth=1)

plt.plot(x, y3, 'k', label='Yahama', linewidth=3)

plt.plot(x, y4, 'y', label='KTM', linewidth=2)

plt.title('Bike details in line plot')

plt.ylabel('Distance in kms')

plt.xlabel('Days')

plt.legend()           #Adding Legends

plt.show()

Bar Plot
x = [50, 60, 30, 70, 20]
y = ["A", "B", "C", "D", "E"]

plt.bar(y, x, color = "green")

plt.show()

Multiple bar plot


x1 = [0.25, 1.25, 2.25, 3.25, 4.25]
y1 = [50, 40, 70, 80, 20]

plt.bar(x1, y1, label="BMW", color='r')

x2 = [.75, 1.75, 2.75, 3.75, 4.75]
y2 = [80, 20, 20, 50, 60]
plt.bar(x2, y2, label="Audi", color='y')
University Institute of Engineering
Department of Computer Science & Engineering

plt.xlabel('Days')
plt.ylabel('Distance (kms)')
plt.title('Information')

plt.legend()
plt.show()

Scatter plot
x = [35, 20, 29, 40, 57]     # x-axis values 
y = [100, 50, 80, 40, 200]         # Y-axis values 

plt.scatter(x, y)         # Function to plot scatter 

plt.xlabel('Salary * 1000')
plt.ylabel('Age)')
plt.title('Age Vs Salary')

plt.show()               # function to show the plot 

Multiple scatter plot


x1 = [1, 1.5, 2, 2.5, 3, 3.5, 3.6]
y1 = [7.5, 8, 8.5, 9, 9.5, 10, 10.5]

x2 = [8, 8.5, 9, 9.5, 10, 10.5, 11]
y2 = [3, 3.5, 3.7, 4, 4.5, 5, 5.2]

plt.scatter(x1, y1, label='High income low saving',  color='r')
plt.scatter(x2, y2, label='Low income high savings', color='b')

plt.xlabel('Saving*100')
plt.ylabel('Income*1000')
plt.title('Scatter Plot')

plt.legend()

plt.grid()
plt.show()       
University Institute of Engineering
Department of Computer Science & Engineering

Pie plot
share = [3,4,2,1]
bikes = ['Enfield','Honda','Yahama','KTM']

plt.pie(share, labels=bikes, shadow= True, explode=(0,0.1,0,0), 
        autopct='%1.1f%%')

plt.title('Bike Shares')

plt.show()

5. Observations, Simulation Screen Shots and Discussions:

a)file handling
1)hello world

2)hello world

3) Writing done !!

Open result.txt to view the content

b)data manipulation
0 1
1 3
2 5
3 7
4 9
5 2
6 4
7 6
8 8
dtype: int64

a 1
b 3
c 5
d 7
e 9
University Institute of Engineering
Department of Computer Science & Engineering

f 2
g 4
h 6
i 8
dtype: int64

Oranges 3
Apples 4
Mangoes 2
Banana 12
dtype: int64
<class 'pandas.core.series.Series'>

0 [1, 3, 5]
1 [2, 4, 6]
dtype: object
CodeText

3)Data visualization
University Institute of Engineering
Department of Computer Science & Engineering
University Institute of Engineering
Department of Computer Science & Engineering
University Institute of Engineering
Department of Computer Science & Engineering

7. Additional Creative Inputs (If Any):

Learning outcomes (What I have learnt):

1.Remember the concepts related to Pandas,create Dataframes and write csv files.

2.Understand the way of execution and debug programs in Python language.

3.Apply various concepts,loops,functions to solve a mathematical and scientific problem.

4.Analyse the data in the dataframe and manipulating it.

5.Design and develop modular programs for real-world problems using control structure and selection
structure.

Evaluation Grid (To be filled by Faculty):


Sr. No. Parameters Marks Obtained Maximum Marks
1. Student Performance (task 12
implementation and result evaluation)
2. Viva-Voce 10
3. Worksheet Submission (Record) 8
Signature of Faculty (with Date): Total Marks Obtained: 30
University Institute of Engineering
Department of Computer Science & Engineering

You might also like