DVTP LAB Manual R21 IT
DVTP LAB Manual R21 IT
DVTP LAB Manual R21 IT
(Autonomous)
NAAC-A Grade, NBA Accredited: Affiliated to JNTUH, Hyderabad
ISO 9001:2008 Certified.
DEPARTMENT OF INFORMATION TECHNOLOGY
Laboratory Manual
of
DATA VISUALIZATION THROUGH PYTHON
(I B.Tech- II SEMESTER)
(VCE-R21)
Course Title DATA VISUALIZATION THROUGH PYTHON Course Type Integrated
I Year II
Course Code A7601 Credits Class
Semester
Contact Work Total Number of
TLP Credits Assessment in
Hours Load Classes
Weight age
Theory 1 1 1 Per Semester
Course
Structure Practice 2 4 4
Theory Practical CIE SEE
- - - -
Total 3 5 5 1 4 30 70
Course Lead: Dr Muni Sekhar Velpuru
Theory Practice
Course
IT IT
Instructors
Dr Muni Sekhar Velpuru Dr Muni Sekhar Velpuru
Mr Anudeep M Mr Anudeep M
Theory: Test-1 1 20
Continuous
Theory: Test-2 1 20
Internal 100 0.3 30
Evaluation (CIE) Alternate
- 20
Assessment*
Practical Exam 2 40
Total 100
COURSE DESCRIPTION:
This course is all about addressing today’s data driven world, in visualizing the data graphically.
Though its foundations are rooted in statistics, many advanced fields of science are practicing it to
explore their large volumes of data and to throw deeper insights of the data. The main aim of this
course is to give better understandings of data and making sense of hidden information using the
basic programming methodology in Python. Visualizing enormous data using graphics can run all
possible unknown stories about data. Data visualization skills learned through this course may raise
the student creativity in presenting projects he encountered. The course uses some of the open
source data Visualization tools.
COURSE OUTCOMES:
At the end of the course student will be able to:
A7601.1 Identify the various building blocks to write a Python program.
A7601.2 Use control statements and build defined functions for solving a given problem by
improving code re-usability.
A7601.3 Implement fundamental data structures for manipulating data.
A7601.4 Implement various visualizations using advanced libraries.
A7601.5 Design suitable visualizations for the given data and infer data insights.
Bloom’s Level
CO# Remember Understand Apply Analyze Evaluate Create
(L1) (L2) (L3) (L4) (L5) (L6)
A7601.1 √
A7601.2 √
A7601.3 √
A7601.4 √
A7601.5 √
COURSE ARTICULATION MATRIX
PO10
PO11
PO12
PSO1
PSO2
CO#/
PO1
PO2
PO3
PO4
PO5
PO6
PO7
PO8
PO9
Pos
A7601.1 3 2 2
A7601.2 3 2 2
A7601.3
2 3 3 3
A7601.4 3 1 1
A7601.5 2 2 2 1 1
COURSE PREREQUISITES:
Problems Solving
Programs
Week 1:
Week 2:
Programs using various operators in Python
a) Write a python program to swap / interchange two numbers with third variableand
without using third variable.
b) Write a program that asks the user for a number of seconds and prints outhow
many minutes and seconds in it. For instance, 200 seconds is 3minutes and20seconds.
c) Write a python program for demonstrating the usage of comparison, unary, shift, logical,
membership and identity operators.
Week 3:
Programs using Conditional Statements & Iterative Statements
(a) Write a python program to check a given number is Even or Odd.
(b) Write a python program to demonstrate nested if and nested if-else to find the
greatest of 3 integer numbers
(c) Write a Python program to find the factorial of a given number.
(d) Write a Python program to reverse the digits of a given number.
(e) Write a python program to display all prime numbers between 0 to n.
(f) Write a program to print all Armstrong numbers between given range using forloop.
(g) Write a Python program to display a simple pyramid pattern for demonstratingnested
loop.
Week 4:
Programs using Strings and Its Operations
(a) Write a program that asks the user to enter a string and perform the following:
i. The total number of characters in the string.
ii. Repeat the string 10 times.
iii. The first character of the string.
iv. The first three characters of the string.
v. The last three characters of the string
vi. The string in backwards.
vii. The seventh character of the string if exist otherwise display a message “Not
exist”.
viii. The string with its first and last characters removed.
ix. The string into capital case
x. The string with every a replaced with ane.
xi. The string with every letter replaced by a space.
(b) Write a python program to read a string and find the number of characters in it.
(Without using Built in Functions).
(c) Write a Python program to read a String and check whether the string is
palindrome or not. (Without using Built in Functions).
Week 5:
Programs using Python Data Structures (Lists).
(e) Write a python program to perform following operations on a list of integers.
i. Write a program that asks the user to enter a string and perform the following:
ii. Print the last item in the list.
iii. Print the list in reverse order.
iv. Print Yes if the list contains a 5 and No otherwise.
v. Print the number of occurrences of a element in the list.
vi. Remove the first and last items from the list and sort the remaining items.
vii. Print how many integers in the list is less than a given value?
viii. Print the average of the elements in the list.
ix. Print the largest and smallest value in the list.
x. Print the second largest and second smallest entries in the list.
xi. Print number of even numbers in the list.
Week 6:
Programs using Python Data Structures (Dictionary).
(a) Write a python program for demonstrating the creation of dictionary, accessing
dictionary elements, modifying dictionary elements, finding length and possible
operations.
(b) Write a python program to create a dictionary of students with keys as roll num-
bers and values as names. Perform operations like insert, update and modify
student data.
(c) Write a program that uses a dictionary that contains ten user names and pass-
words. The program should ask the user to enter username and password. If the
username is not in the dictionary, the program should indicate that the person is “not
a valid user” of the system. If the username is in the dictionary, but the userdoes
not enter the right password, the program should say that “the password is invalid”.
If the password is correct, then the program should display “Welcome”.
Week 7:
Programs using Python Data Structures (Tuples and Set)
a) Write a python program to demonstrate various operations on tuples.
b) Write a python program to demonstrate various operations onsets.
Week 8:
Programs using User Defined Functions.
(a) Write a Python program to calculate simple interest using function
(b) Write a Python program to find the nth term of a Fibonacci number using function.
(c) Write a Python program to find the number of elements in a list using function.
(d) Write a python program to find factorial of a given number using recursion.
(e) Write a python program to find sum of individual digits of a given number using
recursion
Week 9:
Programs using Bar charts and Pie charts.
a) Write a python program to visualize bar and column chart for a given data includes
months on x-axis and prices on y-axis.
b) Write a python program to visualize plot bar charts and histograms for a given 30
students averages.
c) The table given shows the sales of books (in thousand number) from six branchesof
a publishing company during two consecutive years 2000 and 2001.
i. Write a python to display bar graphs of the sales and use different color
foreach bar
ii. Write a python to visualize the percentage of sales using pie chars.
Years B1 B2 B3 B4 B5 B6
2020 80 75 98 83 75 72
2021 105 68 107 95 95 80
Week 10:
Programs using Visualization.
(a) Jerry recorded the temperature in his room (in Degrees Fahrenheit) every two hours
over a 12 hour period from noon to midnight, as Temp=40, 42,45,46,38,36,34. Write a
Python program to visualize the recorded temperatures as line graph.
(b) The population (in thousands) of a town was recorded every twenty years from
1900 to 2000. Population =3, 4,2,5,7,7,7. Write a program to visualize a line graph
by taking years on x-axis.
Week 11:
Programs using Datasets.
a. You are required to construct two datasets with the GPA of two classes each of
60 students.
i. Write a Python program to compare the GPA distribution of each using a
suitable Visualization approach and what can you infer from the distributions.
ii. Write a program to display Boxplot analysis for the same.
b. Write a python program to implement the following on iris data set
i. Visualize the petal length, petal width, sepal length, sepal width.
ii. Visualize average of each.
What can you infer from the visualization? Throw the major insights youhave observed from
the visualizations
Week 12:
Programs using Heat Maps.
a) Write a program to visualize the correlations between various numeric features of
iris data using heat maps.
b) Write a python program to visualize the correlations between various numeric
features of the Titanic data and analyze which features are more important.
Week 13:
Programs using Seaborn.
a) Write a python program to create violin plots of iris species using seaborn
Practice:
1. Implement a program in python to demonstrate the usage of python variables, data
types, operators and I/O
2. Implementing python Decision making and Looping constructs
3. Implementing python data types like lists and tuples.
4. Programs on python string manipulation operations
5. Programs on implementing set and dictionary data types in python
6. Programs on implementing functions and recursion in functions using python
7. Programs on implementing file operations in python
TEXT BOOKS
T1. ReemaThareja. Python Programming using Problem solving Approach. Oxford University
Press, New Delhi India, 2017.
T2. Bajaj Chandrajit, "Data Visualization Techniques", John willey and sons.
T3. Dr.Ossama Embark,"Data Analysis and Visualization using Python", Apress.
REFERENCE BOOKS:
R1. Timothy A Budd. Exploring Python. Tata McGraw Hill Education Private Limited.New
Delhi India, 2008.
R2. Mark Lutz. Learning Python. 5th Edition. O’Reilly, USA, 2015.
R3. Brian Heinold. A Practical Introduction to Python Programming, 2012.
R4. Anthony Banfield, "Thinking Statistically".
Online Tutorials:
http://www.nptel.com
http://www.learnpython.org/
https://docs.python.org/2/tutorial/index.html
http://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python_3/Intro
https://newprediction.com/free-data-visualization-books/
https://www.kaggle.com/learn/data-visualization
https://www.kaggle.com/sanikamal/data-visualization-using-matplotlib
http://www.pythontutor.com/
https://www.datacamp.com/courses/intro-to-python-for-data-science
ASSESSMENT SCHEME
Output:
1(b)Write a python program to read a float value and convert Fahrenheit to Centigrade.
Output:
Output:
Output:
2(a)Write a python program to swap / interchange two numbers with third variable and
without using third variable.
# To take inputs from the user
2{b}Write a program that asks the user for a number of seconds and prints out
how many minutes and seconds in it. For instance, 200 seconds is 3minutes
and20seconds
if hours>=1:
print(hours,"Hours", min-60*hours,"minutes",seconds,"seconds")
else:
print(min,"minutes",seconds,"seconds")
Output:
2(c)Write a python program for demonstrating the usage of comparison, unary, shift,
logical, membership and identity operators.
#Arithmetic Operators
print("Addition =",a + b)
print("Subtraction =",a - b)
print("Multiplication =",a * b)
print("Division =",a / b)
print("Floor Division =",a // b)
print("Modilus =",a % b)
#Comparison Operators
print("is a > b :",a > b)
print("is a < b :",a < b)
print("is a == b :",a == b)
print("is a != b :",a != b)
print("is a >= b :",a >= b)
print("is a <= b :",a <= b)
#Bitwise Operators
print(f"Bitwise AND of {a}, {b} =",a & b)
print(f"Bitwise OR of {a}, {b} =",a | b)
print(f"Bitwise NOT of {a} =",~a)
print(f"Bitwise XOR of {a}, {b} =",a ^ b)
print(f"Bitwise Right shift of {a} =",a >> 2)
print(f"Bitwise Left shift of {a} =",a << 2)
#Identity Operator
print("if the operands are not identical ",a is not b)
print("if the operands are identical ",a is b)
list = [10, 20, 30, 40, 50]
if (a not in list):
print("x is NOT present in given list")
else:
print("x is present in given list")
if (b in list):
print("y is present in given list")
else:
print("y is NOT present in given list")
Output:
Output:
3(b) Write a python program to demonstrate nested if and nested if-else to find the greatest of
3 integer numbers
Output:
Output:
Output:
Output:
3(f)Write a python program to display all Armstrong numbers between min to max
Output:
Output:
4(a) Write a program that asks the user to enter a string and perform the following:
Output:
Enter the stringStudents of R21 Batch
Length of String 21
Output:
Output:
first character = S
Output:
first three character = Stud
Output:
last three character = tch
Output:
The string in backwards hctaB 12R fo stnedut
# vii. The seventh character of the string if exist otherwise display a message “Not exist”
if len(string)>=7:
print('seventh character =',string[6])
else:
print("value does Not exist")
Output:
seventh character = t
# viii. The string with its first and last characters removed.
print('string with its first and last characters removed.',string[1:-1])
Output:
string with its first and last characters removed. tudents of R21 Batc
Output:
string into capital case STUDENTS OF R21 BATCH
Output:
string with every a replaced with ane Students of R21 Banetch
Output:
string with every letter replaced by a space 21
4(b)Write a python program to read a string and find the number of characters in it. (Without
using Built in Functions).
Output:
4(c)Write a Python program to read a String and check whether the string is palindrome or not.
#(Without using Built in Functions).
Output:
Output:
Output:
Output:
Output:
Output:
# vi. Remove the first and last items from the list and sort the remaining items.
_,*mid,_=ls
#mid=ls[1:-1]
print("list before removing first and last items ",ls)
print("list before sorting ",mid)
mid.sort()
print("sorted list after removing first and last items ",mid)
Output:
# vii. Print how many integers in the list is less than a given value?
Output:
total = 0
# Finding the sum sum(ls)
for i in ls:
total += i
# divide the total elements by number of elements
avg = total/len(ls)
print("sum = ", total)
print("average = ", avg)
Output:
Output:
# x. Print the second largest and second smallest entries in the list.
largest = ls[0]
lowest = ls[0]
largest2 = None
lowest2 = None
for item in ls[1:]:
if item > largest:
largest2 = largest
largest = item
elif largest2 is None or largest2 < item:
largest2 = item
if item < lowest:
lowest2 = lowest
lowest = item
elif lowest2 is None or lowest2 > item:
lowest2 = item
print("Largest element is:", largest)
print("Smallest element is:", lowest)
print("Second Largest element is:", largest2)
'''Anoher method
#second largest
for i in l1[::-1]:
if(max(l1)>i):
print(i)
break
#second min
for i in l1:
if(min(l1)<i):
print(i)
break'''
Output:
c=0
for evn in ls:
# check
if evn % 2 == 0:
c=c+1
print(evn, end = " ")
print("Total no of Even numbers =",c)
Output:
Dc1 = {}
n=int(input('enter range'))
Dc1[1] = 'Vardhaman'
for i in range(2,n):
v=input(f'enter {i} value ')
Dc1[i]=v
print(Dc1)
print('len =',len(Dc1))
print('min = ',min(Dc1))
print('max = ',max(Dc1))
print('sum = ',sum(Dc1))
print(Dc1.values())
print(Dc1.keys())
print(Dc1.items())
print(Dc1.get(3))
print(Dc1)
Output:
(b) Write a python program to create a dictionary of students with keys as roll numbers and
values as names. Perform operations like insert, update and modify student data
stud_le={'1205':'guna','1206':'ravi','1207':'madu'}
Output:
(C) Write a program that uses a dictionary that contains ten user names and passwords. The
program should ask the user to enter username and password. If the username is not in the
dictionary, the program should indicate that the person is “not a valid user” of the system. If
the username is in the dictionary, but the user does not enter the right password, the program
should say that “the password is invalid”. If the password is correct, then the program should
display “Welcome”
login={'ram': 1234, 'sam': 5678, 'raj': 4567, 'manu': 9876, 'ford': 7849,
'tata': 4568, 'google': 7412, 'amazon': 41263, 'yahoo': 7854,
'facebook': 1452}
uname=input("enter username ")
password=int(input("enter password "))
if uname in login:
if login.get(uname)==password:
print("Successfully logedin Welcome")
else:
print("this password is invalid ")
else:
print("not a valid user")
Output:
# Print Yes if tuple contains value 5 along with its index, else print No otherwise.
if 5 in t:
print("Yes the element is present at location ",t.index(5))
else:
print("No")
# Print how many integers in the tuple are less than a given value?
element=int(input("Enter an element to check:"))
x=0
for i in t:
if(i<element):
x+=1
print(f"Elements less than {element}:",x)
Output:
s.add(5)
print('Updated set after add:', s)
s.discard(5)
print('Updated set_after discard:', s)
s.remove(1)
print('Updated set after remove:', s)
t.intersection_update(u)
print(f"Intersection of set {t} and {u}: ",t)
u.symmetric_difference_update(s)
print(f"Symmetric Difference of set {u} and {s}: ",u)
s.clear()
print('Updated set after clear:', s)
Output:
def c_intrest(p,t,r):
#compute compound interest
ci = p * (pow((1 + r / 100), t))
return ci
Output:
(b) Write a Python program to find the nth term of a Fibonacci number using function
def fib2(n):
a,b=0,1
#print(a,b,end=' ')
for i in range(n):
f=a+b
a=b
b=f
print(f,end=' ')
fib2(int(input("enter value")))
Output:
(c) Write a Python program to find the number of elements in a list using function.
def count_list(ls1):
c=0
for i in ls1:
c=c+1
return c
ls1=[1,2,3,'hello',56.2,'welcome']
print('The number of elements in list are = ',count_list(ls1))
Output:
(d) Write a python program to find factorial of a given number using recursion.
Output:
(e) Write a python program to find sum of individual digits of a given number using recursio
tot = 0
Reminder=5
def sum_of_num(Num):
global tot
if(Num > 0):
Reminder = Num % 10
tot = tot + Reminder
sum_of_num(Num //10)
return tot
Output:
Years B1 B2 B3 B4 B5 B6
2020 80 75 98 83 75 72
(a) Write a python program to visualize bar and column chart for a given data includes months
on x-axis and prices on y-axis.
import pandas as pd
from matplotlib import pyplot as plt
y=[10,1.2,4.3,3.4,7.5,2.5]
plt.xlabel('months')
plt.ylabel('price')
plt.bar(x,y)
plt.show()
Output:
(b) Write a python program to visualize plot bar charts and histograms for a given 30 students
averages.
import pandas as pd
from matplotlib import pyplot as plt
avg=(dp['Theory']+dp['Lab'])/2
print(avg.plot(kind='bar'))
Output:
import pandas as pd
from matplotlib import pyplot as plt
plt.legend()
plt.show()
Output:
i. Write a python to display bar graphs of the sales and use different color for each bar
plt.legend()
plt.show()
Output:
ii. Write a python to visualize the percentage of sales using pie chars.
import pandas as pd
from matplotlib import pyplot as plt
plt.figure(0)
plt.pie(y, labels = ['Branch 1','Branch 2','Branch 3','Branch 4','Branch 5','Branch 6'],
autopct='%.0f%%')
plt.title('Sales in 2000')
plt.figure(1)
plt.pie(z, labels = x, autopct='%.0f%%')
plt.title('Sales in 2001')
plt.show()
Output:
(a) Jerry recorded the temperature in his room (in Degrees Fahrenheit) every two hours over a
12 hour period from noon to midnight, as Temp=40, 42,45,46,38,36,34. Write a Python
program to visualize the recorded temperatures as line graph.
import pandas as pd
from matplotlib import pyplot as plt
Output:
Vardhaman College of Engineering Data Visualization through Python
(b) The population (in thousands) of a town was recorded every twenty years from 1900 to
2000. Population =3, 4,2,5,7,7,7. Write a program to visualize a line graph by taking years on x-
axis.
import pandas as pd
from matplotlib import pyplot as plt
plt.xlabel('Year')
plt.ylabel("Population in thousands")
plt.plot(year,pepl)
plt.show()
Output:
(a) You are required to construct two datasets with the GPA of two classes each of 60 students.
i. Write a Python program to compare the GPA distribution of each using a suitable
Visualization approach and what can you infer from the distributions.
GPA_set.plot(kind='box')
plt.show()
i. Visualize the petal length, petal width, sepal length, sepal width.
iris=load_iris()
iris
Output:
import pandas as pd