0% found this document useful (0 votes)
51 views53 pages

DVP PDF

DVP 2nd year

Uploaded by

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

DVP PDF

DVP 2nd year

Uploaded by

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

K.S.

SCHOOL OF ENGINEERIN AND MANAGEMENT,


BENGALURU

DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS

DATA VISUALIZATION WITH PYTHON (BCS358D)

Prepared by: -

Mr. Ramesh Babu N Mrs. Frinkly T


Associate Professor Assistant Professor
Dept. of CS & BS, Dept. of CS & BS,
KSSEM KSSEM

LAB MANUAL

ACADEMIC YEAR 2023 – 2024


Institution Vision & Mission

VISION: “To impart quality education in engineering and management to meettechnological,


business and societal needs through holistic education and research”

MISSION:
K.S. School of Engineering and Management shall,
 Establish state-of-art infrastructure to facilitate effective dissemination of technical and
Managerial knowledge.
 Provide comprehensive educational experience through a combination of curricular and
experiential learning, strengthened by industry-institute- interaction.
 Pursue socially relevant research and disseminate knowledge.
 Inculcate leadership skills and foster entrepreneurial spirit among students.

Department Vision & Mission

VISION: “To provide competent learning ecosystem to develop the understanding of


technology and business to produce innovative, principled and insightful leadersto meet the
societal demands.”

MISSION:
 To deliver high-quality education in the fields of technology and businessthrough
effective teaching-learning practices and a conducive learning environment.
 To create the centre of excellence through collaborations with industries andvarious
entities, addressing the evolving demands of society.
 To foster an environment that promotes innovation, multidisciplinary research,skill
enhancement and entrepreneurship.
 To uphold and advocate for elevated standards of professional ethics and
transparency.
DATA VISUALIZATION WITH PYTHON (BCS358D)

Data Visualization with Python Semester III


Course Code BCS358D CIE Marks 50
Teaching Hours/Week (L:T:P: S) 0: 0: 2: 0 SEE Marks 50
Credits 0 Exam Hours 100
1
Examination type (SEE) Practical
Course objectives:
● CLO 1. Demonstrate the use of IDLE or PyCharm IDE to create Python Applications
● CLO 2. Using Python programming language to develop programs for solving real-world problems

● CLO 3. Implementation of Matplotlib for drawing different Plots

● CLO 4. Demonstrate working with Seaborn, Bokeh.


● CLO 5. Working with Plotly for 3D, Time Series and Maps.
Experiments
Sl. PART A – List of problems for which student should develop program and execute in theLaboratory
No.
1 a) Write a python program to find the best of two test average marks out of three test’s marks accepted from
the user.
b) Develop a Python program to check whether a given number is palindrome or not andalso count the
number of occurrences of each digit in the input number.

Datatypes: https://www.youtube.com/watch?v=gCCVsvgR2KU Operators:


https://www.youtube.com/watch?v=v5MR5JnKcZI Flow Control:
https://www.youtube.com/watch?v=PqFKRqpHrjwFor loop: https://www.youtube.com/watch?v=0ZvaDa8eT5s
While loop: https://www.youtube.com/watch?v=HZARImviDxg Exceptions:
https://www.youtube.com/watch?v=6SPDvPK38tw

2 a) Defined as a function F as Fn = Fn-1 + Fn-2. Write a Python program which accepts a value for N (where N
>0) as input and pass this value to the function. Display suitable error message if the condition for input value
is not followed.
b) Develop a python program to convert binary to decimal, octal to hexadecimal using functions.

Functions:https://www.youtube.com/watch?v=BVfCWuca9nw
Arguments:https://www.youtube.com/watch?v=ijXMGpoMkhQ Return
value: https://www.youtube.com/watch?v=nuNXiEDnM44

Dept of CS & BS, KSSEM 1


DATA VISUALIZATION WITH PYTHON (BCS358D)

3 a) Write a Python program that accepts a sentence and find the number of words, digits, uppercase letters and
lowercase letters.
b) Write a Python program to find the string similarity between two given strings

Sample Output: Sample Output:


Original string: Original string:
Python Exercises Python Exercises
Python Exercises Python Exercise
Similarity between two said strings: Similarity between two said strings:1.0
0.967741935483871
Strings: https://www.youtube.com/watch?v=lSItwlnF0eU
String functions: https://www.youtube.com/watch?v=9a3CxJyTq00

4 a) Write a Python program to Demonstrate how to Draw a Bar Plot using Matplotlib.
b) Write a Python program to Demonstrate how to Draw a Scatter Plot using Matplotlib.

https://www.youtube.com/watch?v=RRHQ6Fs1b8w&list=PLjVLYmrlmjGcC0B_FP3bkJ-
JIPkV5GuZR&index=3
https://www.youtube.com/watch?v=7ABCuhWO9II&list=PLjVLYmrlmjGcC0B_FP3bkJ-
JIPkV5GuZR&index=4

5
a) Write a Python program to Demonstrate how to Draw a Histogram Plot using Matplotlib.
b) Write a Python program to Demonstrate how to Draw a Pie Chart using Matplotlib.

https://www.youtube.com/watch?v=Qk7caotaQUQ&list=PLjVLYmrlmjGcC0B_FP3bkJ-
JIPkV5GuZR&index=6
https://www.youtube.com/watch?v=PSji21jUNO0&list=PLjVLYmrlmjGcC0B_FP3bkJ-
JIPkV5GuZR&index=7

a) Write a Python program to illustrate Linear Plotting using Matplotlib.


b) Write a Python program to illustrate liner plotting with line formatting using Matplotlib.

https://www.youtube.com/watch?v=UO98lJQ3QGI&list=PL-osiE80TeTvipOqomVEeZ1HRrcEvtZB_

7
Write a Python program which explains uses of customizing seaborn plots with Aesthetic functions.

https://www.youtube.com/watch?v=6GUZXDef2U0

8 Write a Python program to explain working with bokeh line graph using Annotations and Legends.

a) Write a Python program for plotting different types of plots using Bokeh.

https://www.youtube.com/watch?v=HDvxYoRadcA

Dept of CS & BS, KSSEM 2


DATA VISUALIZATION WITH PYTHON (BCS358D)

9 Write a Python program to draw 3D Plots using Plotly Libraries.

https://www.youtube.com/watch?v=cCck7hCanpw&list=PLE50-dh6JzC4onX-
qkv9H3HtPbBVA8M94&index=4

10 a) Write a Python program to draw Time Series using Plotly Libraries.


b) Write a Python program for creating Maps using Plotly Libraries.

https://www.youtube.com/watch?v=xnJ2TNrGYik&list=PLE50-dh6JzC4onX-
qkv9H3HtPbBVA8M94&index=5

https://www.youtube.com/watch?v=D35m2CdMhVs&list=PLE50-dh6JzC4onX-
qkv9H3HtPbBVA8M94&index=6
Python (Full Course): https://www.youtube.com/watch?v=_uQrJ0TkZlc
Pedagogy For the above experiments the following pedagogy can be considered. Problem
based learning, Active learning, MOOC, Chalk &Talk
Course outcomes (Course Skill Set):
At the end of the course the student will be able to:
CO 1. Demonstrate the use of IDLE or PyCharm IDE to create Python Applications
CO 2. Use Python programming constructs to develop programs for solving real-world problemsCO 3.
Use Matplotlib for drawing different Plots
CO 4. Demonstrate working with Seaborn, Bokeh for visualization.
CO 5. Use Plotly for drawing Time Series and Maps.

Assessment Details (both CIE and SEE)


The weightage of Continuous Internal Evaluation (CIE) is 50% and for Semester End Exam (SEE) is 50%. The
minimum passing mark for the CIE is 40% of the maximum marks (20 marks out of 50) and for the SEE minimum
passing mark is 35% of the maximum marks (18 out of 50 marks). A student shall be deemed to have satisfied the
academic requirements and earned the credits allotted to each subject/ course if the student secures a minimum of
40% (40 marks out of 100) in the sum total of the CIE (Continuous Internal Evaluation) and SEE (Semester End
Examination) taken together

Continuous Internal Evaluation (CIE):


CIE marks for the practical course are 50 Marks.
The split-up of CIE marks for record/ journal and test are in the ratio 60:40.
● Each experiment is to be evaluated for conduction with an observation sheet and recordwrite-up.
Rubrics for the evaluation of the journal/write-up for hardware/software experiments are
designed by the faculty who is handling the laboratory session and are made known to students at
the beginning of the practical session.
● Record should contain all the specified experiments in the syllabus and each experimentwrite-up
will be evaluated for 10 marks.
● Total marks scored by the students are scaled down to 30 marks (60% of maximummarks).
● Weightage to be given for neatness and submission of record/write-up on time.
● Department shall conduct a test of 100 marks after the completion of all the experiments listed in
Dept of CS & BS, KSSEM 3
DATA VISUALIZATION WITH PYTHON (BCS358D)

the syllabus.
● In a test, test write-up, conduction of experiment, acceptable result, and procedural knowledge
will carry a weightage of 60% and the rest 40% for viva-voce.
● The suitable rubrics can be designed to evaluate each student’s performance and learning ability.
● The marks scored shall be scaled down to 20 marks (40% of the maximum marks).
The Sum of scaled-down marks scored in the report write-up/journal and marks of a test is the total CIE
marks scored by the student.
Semester End Evaluation (SEE):

SEE marks for the practical course are 50 Marks.


SEE shall be conducted jointly by the two examiners of the same institute, examiners are
appointed by the Head of the Institute.

The examination schedule and names of examiners are informed to the university before
the conduction of the examination. These practical examinations are to be conducted
between the schedule mentioned in the academic calendar of the University.
All laboratory experiments are to be included for practical examination.
(Rubrics) Breakup of marks and the instructions printed on the cover page of the answer
script to be strictly adhered to by the examiners. OR based on the course requirement
evaluation rubrics shall be decided jointly by examiners.
Students can pick one question (experiment) from the questions lot prepared by the
examiners jointly.

Evaluation of test write-up/ conduction procedure and result/viva will be conducted


jointly by examiners.

General rubrics suggested for SEE are mentioned here, writeup-20%, Conduction
procedure and result in -60%, Viva-voce 20% of maximum marks. SEE for practical shall
be evaluated for 100 marks and scored marks shall be scaled down to 50 marks (however,
based on course type, rubrics shall be decided by the examiners)

Change of experiment is allowed only once and 15% of Marks allotted to the procedure
part are to be made zero.
The minimum duration of SEE is 02 hours
● Weightage of marks for PART A is 80% and for PART B is 20%. General rubrics
suggested to be followed for part A and part B.
● Change of experiment is allowed only once and Marks allotted to the procedure part to
be made zero (Not allowed for Part B).
● The duration of SEE is 03 hours
Rubrics suggested in Annexure-II of Regulation book

Dept of CS & BS, KSSEM 4


DATA VISUALIZATION WITH PYTHON (BCS358D)

Textbooks:
1. Al Sweigart, “Automate the Boring Stuff with Python”,1stEdition, No Starch Press,
2015. (Available under CC-BY-NC-SA license at https://automatetheboringstuff.com/)
2. Reema Thareja “Python Programming Using Problem Solving Approach” Oxford University
Press.
3. Allen B. Downey, “Think Python: How to Think Like a Computer Scientist”,
2nd Edition, Green Tea Press, 2015. (Available under CC-BY-NC license
at http://greenteapress.com/thinkpython2/thinkpython2.pdf)
4. Jake VanderPlas “Python Data Science Handbook” 1st Edition, O’REILLY.
Semester End Evaluation (SEE):
SEE marks for the practical course are 50 Marks.
SEE shall be conducted jointly by the two examiners of the same institute, examiners are appointed
by the Head of the Institute.

The examination schedule and names of examiners are informed to the university before the
conduction of the examination. These practical examinations are to be conducted
between the schedule mentioned in the academic calendar of the University. All laboratory
experiments are to be included for practical examination.
(Rubrics) Breakup of marks and the instructions printed on the cover page of the answer script to be
strictly adhered to by the examiners. OR based on the course requirement evaluation rubrics shall be
decided jointly by examiners.

Students can pick one question (experiment) from the questions lot prepared by the examiners
jointly.

Evaluation of test write-up/ conduction procedure and result/viva will be conducted jointly by
examiners.

General rubrics suggested for SEE are mentioned here, writeup-20%, Conduction procedure and
result in -60%, Viva-voce 20% of maximum marks. SEE for practical shall
be evaluated for 100 marks and scored marks shall be scaled down to 50 marks (however, based on
course type, rubrics shall be decided by the examiners)

Change of experiment is allowed only once and 15% of Marks allotted to the procedure part are
to be made zero.
The minimum duration of SEE is 02 hours
● Weightage of marks for PART A is 80% and for PART B is 20%. General rubrics
suggested to be followed for part A and part B.
● Change of experiment is allowed only once and Marks allotted to the procedure part to
be made zero (Not allowed for Part B).
● The duration of SEE is 03 hours
Rubrics suggested in Annexure-II of Regulation book

Dept of CS & BS, KSSEM 5


DATA VISUALIZATION WITH PYTHON (BCS358D)

Textbooks:
5. Al Sweigart, “Automate the Boring Stuff with Python”,1stEdition, No Starch Press,
2015. (Available under CC-BY-NC-SA license at https://automatetheboringstuff.com/)
6. Reema Thareja “Python Programming Using Problem Solving Approach” Oxford University
Press.
7. Allen B. Downey, “Think Python: How to Think Like a Computer Scientist”,
2nd Edition, Green Tea Press, 2015. (Available under CC-BY-NC license at
http://greenteapress.com/thinkpython2/thinkpython2.pdf)
8. Jake VanderPlas “Python Data Science Handbook” 1st Edition, O’REILLY.

Dept of CS & BS, KSSEM 6


DATA VISUALIZATION WITH PYTHON (BCS358D)

K.S. SCHOOL OF ENGINEERING AND MANAGEMENT


BANGALORE - 560109
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS

CO-PO Mapping
Course: Data Visualization with Python Course Code: BCS358D
No of
Hours
Practical/Field Total Number of
Lab Hours Total hours/Week
Work/Allied LabContact
Activities Hours
2 0 2 28
Marks
CIE SEE Total Credit
s
50 50 100 01
Aim/Objectives of the Course
This laboratory course enables students to get practical experience in design, develop, implement,
analyzeand evaluation/testing of
1. Demonstrate the use Python programming constructs to develop
programsfor solving real-world problems.
2. Identify the different functions of Matplotlib for drawing different Plots.
3. Demonstrate working with Seaborn, Bokeh for visualization.
4. Discover the need of Plotly for drawing Time Series and Maps.

Course Learning Outcomes


After completing the course, the students will be able to

Demonstrate the use of IDLE or PyCharm IDE to create


CO1 Python Applications. Applying (K3)

Use Python programming constructs to develop Applying (K3)


CO2 programs forsolving real-world problems

Implemention of Matplotlib for drawing different Plots. Applying (K3)


CO3

Demonstrate working with Seaborn, Bokeh for Applying (K3)


CO4 datavisualization

Dept of CS & BS, KSSEM 7


DATA VISUALIZATION WITH PYTHON (BCS358D)

CO5 Apply Plotly for drawing Time Series and Maps Applying (K3)

Syllabus
Content
CO1, CO2
2 hrs
Program – 1
PO1-3
a) Write a python program to find the best of two test average marks out of PO2-3
PO3-2
three test’s marks acceptedfrom the user. PO4-1
PO5-3
PO8-2
b) Develop a Python program to check whether a given number is PO9-1
PO12 -
palindrome or not and also count the number of occurrences of each digit
1PSO1-
in the input number. 2PSO2-
2
CO1, CO2
Program – 2 2 hrs

a) Defined as a function F as Fn = Fn-1 + Fn-2. Write a Python program PO1-3


PO2-3
which accepts a value for N (where N >0) as input and pass this value
PO3-2
to the function. Display suitable error message if the condition for PO4-1
input value is not followed. PO5-3
PO8-2
PO9-1
PO12 -
b) Develop a python program to convert binary to decimal, octal to 1PSO1-
hexadecimal using functions. 2PSO2-
2

CO1,CO2
2 hrs
Program – 3
PO1-3
a) Write a Python program that accepts a sentence and find the PO2-3
number ofwords, digits, uppercase letters andlowercase letters. PO3-2
PO4-1
PO5-3
PO8-2
b) Write a Python program to find the string similarity between two
givenstrings. PO9-1
PO12 -
1PSO1-
2PSO2-
2

Dept of CS & BS, KSSEM 8


DATA VISUALIZATION WITH PYTHON (BCS358D)

Program – 4 CO3
2 hrs
a) Write a Python program to Demonstrate how to Draw a Bar Plot
usingMatplotlib. PO1-3
b) Write a Python program to Demonstrate how to Draw a Scatter Plot PO2-3
PO3-2
usingMatplotlib.
PO4-1
PO5-3
PO8-2
PO9-1
PO12 -
1PSO1-
3
PSO2-3
CO3
Program – 5 2 hrs
a) Write a Python program to Demonstrate how to Draw a Histogram PO1-3
Plotusing Matplotlib. PO2-3
b) Write a Python program to Demonstrate how to Draw a Pie Chart PO3-2
PO4-1
usingMatplotlib.
PO5-3
PO8-2
PO9-1
PO12 -1
PSO1-3
PSO2-3
CO3
Program – 6 2 hrs

a) Write a Python program to illustrate Linear Plotting using Matplotlib. PO1-3


b) Write a Python program to illustrate liner plotting with line PO2-3
PO3-2
formattingusing Matplotlib. PO4-1
PO5-3
PO8-2
PO9-1
PO12 -
1PSO1-
3
PSO2-3

Dept of CS & BS, KSSEM 9


DATA VISUALIZATION WITH PYTHON (BCS358D)

CO4
Program – 7 2 hrs
PO1-3
a) Write a Python program which explains uses of customizing seaborn PO2-3
plotswith Aesthetic functions. PO3-2
PO4-1
PO5-3
PO8-2
PO9-1
PO12 -1
PSO1-3
PSO2-3

CO4
Program – 8 2 hrs
Write a Python program to explain working with bokeh line graph using PO1-3
Annotations and Legends. PO2-3
PO3-2
a) Write a Python program for plotting different types of plots using Bokeh. PO4-1
PO5-3
PO8-2
PO9-1
PO12 -1
PSO1-3
PSO2-3
CO5
Program – 9 2 hrs
Write a Python program to draw 3D Plots using Plotly Libraries. PO1-3
PO2-3
PO3-2
PO4-1
PO5-3
PO8-2
PO9-1
PO12 -1
PSO1-3
PSO2-3
CO5
Program – 10 2 hrs
a) Write a Python program to draw Time Series using Plotly Libraries. PO1-3
b) Write a Python program for creating Maps using Plotly Libraries. PO2-
PO32
PO4-1
PO5-3
PO8-2
PO9-1
PO12 -1
PSO1-3
PSO2-3

Dept of CS & BS, KSSEM 10


DATA VISUALIZATION WITH PYTHON (BCS358D)

CO to PO Mapping

PO1: Science and engineering PO7:Environment and Sustainability


Knowledge PO8:Ethics
PO2: Problem Analysis PO9:Individual & Team Work
PO3: Design & Development PO10: Communication
PO11:Project Management & Finance
PO4:Investigations of Complex
PO12:Lifelong Learning
Problems
PO5: Modern Tool Usage
PO6: Engineer & Society

PSO1: Understand fundamental and advanced concepts in the core areas of Computer Science and
Engineering to analyze, design and implement the solutions for the real-world problems.
PSO2: Utilize modern technological innovations efficiently in various applications to work
towards the betterment of society and solve engineering problems.

CO PO PO PO1 PSO PSO


PO PO2 PO3 PO4 PO5 PO6 PO7 PO9 PO11 PO12
1 8 0 1 2

BCS K-
304 level

CO1 K3 3 3 2 1 3 - - 2 1 - - 1 2 2
CO2 K3 3 3 2 1 3 - - 2 1 - - 1 2 2
CO3 K3 3 3 2 1 3 - - 2 1 - - 1 3 3
CO4 K3 3 3 2 1 3 - - 2 1 - - 1 3 3
CO5 K3 3 3 2 1 3 - - 2 1 - - 1 3 3

Dept of CS & BS, KSSEM 11


DATA VISUALIZATION WITH PYTHON (BCS358D)

Program1a:
Write a python program to find the best of two test average marks out of three test’s marks accepted from
the user.

#Read Test marks


test1 = float (input ("Enter Test1 marks: "))
test2 = float (input ("Enter Test2 marks: "))
test3 = float (input ("Enter Test3 marks: "))

#Copy data to marks list


marks= []
marks.append(test1)
marks.append(test2)
marks.append(test3)
print(marks)

#Sort marks
marks.sort (reverse=1)
print("\n Marks after sorting")
print(marks)

#Find Average
avg = ((marks [0] +marks [1]))/2
print("\n The average marks of the student: ", avg)

Output:
Enter Test1 marks: 34
Enter Test2 marks: 35
Enter Test3 marks: 36
[34.0, 35.0, 36.0]

Marks after sorting


[36.0, 35.0, 34.0]

The average marks of the student: 35.5

#Alternate Program
n=3 #No. of Tests
marks = []

for i in range(0,n):
test_mark = float(input("Enter the marks:"))
marks.append(test_mark)

marks.sort(reverse=True)
print("Best of two average test marks:", (marks[0] + marks[1])/2 )

Dept of CS & BS, KSSEM 12


DATA VISUALIZATION WITH PYTHON (BCS358D)

Output:
Enter the marks:2
Enter the marks:4
Enter the marks:6
Best of two average test marks: 5.0

Program1b:
Develop a Python program to check whether a given number is palindrome or not and also count the number
of occurrences of each digit in the input number.
num = input("Enter a number: ")

#Check whether num is palindrome or not


if (num == num[ : : -1]):
print("Number is a Palindrome.")
else:
print("Number is NOT a Palindrome.")

#Counting number of occurances


print("Number: ",num)
for i in range (10): # 0-9
if num.count(str(i)) > 0:
print(str(i), "appears", num.count(str(i)), "times.")

Output:
Enter a number: 112211
Number is a Palindrome.
Number: 112211
1 appears 4 times.
2 appears 2 times.

# Alternate Program
#Read num
num = input("Enter the number: ")

#num_list = list(num)
rev_num = num[::-1] # reverse num

if num == rev_num :
print("The number is a palindrome")
else:
print("the number is not a palindrome")

# count number of occurences of digits


counter = dict()
for i in num:
if counter.get(i) == None:
counter[i] = 1
else:
counter[i] = counter[i]+1

#Display result
Dept of CS & BS, KSSEM 13
DATA VISUALIZATION WITH PYTHON (BCS358D)

for k,v in counter.items():


print(k, "is found", v, "times")

Output:
Enter the number: 44544
The number is a palindrome
4 is found 4 times
5 is found 1 times

Dept of CS & BS, KSSEM 14


DATA VISUALIZATION WITH PYTHON (BCS358D)

Program 2a:
Defined as a function F as Fn = Fn-1 + Fn-2. Write a Python program which accepts a value for N (where N
>0) as input and pass this value to the function. Display suitable error message if the condition for input
value is not followed.

def F(n):
if n == 0 or n == 1:
return 1
else:
return F(n-1) + F(n-2)

num = int (input ("Enter the value of N: "))


if num > 0:
fib = F(num)
print ("Fibonacci value at nth position is: ", fib)
else:
print ("Incorrect value of N")

Output:
Enter the value of N: 5
Fibonacci value at nth position is: 8

Program 2b:
Develop a python program to convert binary to decimal, octal to hexadecimal using functions.

#Function to convert binary number to decimal number


def bin_to_decimal (num):
decimal_num = 0
exp = -1
for digit in num[::-1]:
exp = exp + 1

if(int(digit) == 1):
decimal_num = decimal_num + 2 ** exp;
elif(int(digit) == 0):
continue

else:
print("Invalid input.")
return -1
return decimal_num

#Function to convert octal to decimal to hexadecimal number


def oct_to_hex (num):
dec_value = 0
base = 1
temp = num

while temp:
Dept of CS & BS, KSSEM 15
DATA VISUALIZATION WITH PYTHON (BCS358D)

last_digit = temp % 10
dec_value += last_digit * base

base = base * 8
temp = temp // 10

return dec_hex(dec_value)

#Function to convert Decimal to Hexadecimal number


def dec_hex(n):
hexaDeciNum = ''

while n != 0:
temp = 0
temp = n % 16
if temp < 10:
hexaDeciNum = str(temp) + hexaDeciNum
else:
hexaDeciNum = chr(temp + 87) + hexaDeciNum
n = n // 16

return hexaDeciNum

# Read and convert binary to decimal


binary_no = input("\nEnter a binary number: ")
decimal_no = bin_to_decimal(binary_no)
print ("\nDecimal Equivalent ", decimal_no)

# Read and convert octal to hexadecimal


octal_no = int(input("\nEnter a octal number: "))
hex_no = oct_to_hex(octal_no)
#print ("\nHexadecimal Equivalent ", hex_no)
print ("\nHexadecimal Equivalent ", "0x"+str(hex_no))

Output:
Enter a binary number: 1010

Decimal Equivalent 10

Enter a octal number: 56

Hexadecimal Equivalent 0x2e

Dept of CS & BS, KSSEM 16


DATA VISUALIZATION WITH PYTHON (BCS358D)

Program 3a:
Write a Python program that accepts a sentence and find the number of words, digits, uppercase letters and
lowercase letters.
sentence = input ("Enter the Sentence ")

w, d, l, u = 0, 0, 0, 0

#Find number of words


words = sentence.split()
w = len (words)

#Find number of digits, uppercase and lowercase symbols


for ch in sentence:
if ch.isdigit():
d=d+1
elif ch.isupper():
u=u+1
elif ch.islower():
l=l+1

#Print Outputs
print ("Number of words", w)
print ("Number of Digits", d)
print ("Number of Uppercase Letters", u)
print ("Number of Lowercase Letters", l)

Output:
Enter the Sentence HELLO PYTHON
Number of words 2
Number of Digits 0
Number of Uppercase Letters 11
Number of Lowercase Letters 0

#Alternate Program
sentence = input ("Enter the Sentence ")

words = sentence.split()
#print("Number of words:",len(words))

digits = []
u_letters = []
l_letters = []
spl_chars = []

for ch in sentence:
if ch.isdecimal():
digits.append(ch)
elif ch.isupper():
u_letters.append(ch)
elif ch.islower():
Dept of CS & BS, KSSEM 17
DATA VISUALIZATION WITH PYTHON (BCS358D)

l_letters.append(ch)
else:
spl_chars.append(ch)

#print(digits,u_letters,l_letters,spl_chars)
print("Number of Words : ",len(words))
print("Number of Digits : ",len(digits))
print("Number of Upper case letters : ",len(u_letters))
print("Number of Lower case letters : ",len(l_letters))

Output:
Enter the Sentence Welcome to KSSEM 01-11-2023
Number of Words : 4
Number of Digits : 8
Number of Upper case letters : 6
Number of Lower case letters : 8

Program 3b:
Write a Python program to find the string similarity between two given strings.
from difflib import SequenceMatcher

str1 = input ("Enter the first string :")


str2 = input ("Enter the second string :")

print ("Similarity score: ")


print(SequenceMatcher(None, str1, str2).ratio())

Output:
Enter the first string :hello
Enter the second string :Hello
Similarity score:
0.8

Dept of CS & BS, KSSEM 18


DATA VISUALIZATION WITH PYTHON (BCS358D)

Program 4a:
Write a Python program to Demonstrate how to Draw a Bar Plot using Matplotlib.
# Profit made on product1 and Product2 on different days
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']
p1_sales = [1, 2, 3, 4, 5, 6, 7]
p2_sales = [5, 3, 6, 2, 3, 6, 5]

x_axis = np.arange(len(days))

#Plot Bar Graph


plt.bar(x_axis - 0.2, p1_sales, color='blue', width=0.4)
plt.bar(x_axis + 0.2, p2_sales, color='red', width=0.4)

#Add labels and title


plt.xlabel("Days", fontsize=12)
plt.ylabel("Profit(Cr.)", fontsize=12)

plt.xticks(x_axis, days)
#plt.set_ylim(0, 10)

#Display the plot


plt.show()

Output:

Dept of CS & BS, KSSEM 19


DATA VISUALIZATION WITH PYTHON (BCS358D)

#Alternate program
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']
values = [13, 89, 78, 73, 90, 23, 67]

#Plot Bar Graph


plt.bar(days, values, color='blue',width=0.5)

#Add labels and title


plt.xlabel("Days", fontsize=12)
plt.ylabel("Profit(Cr.)", fontsize=12)

#Display the plot


plt.show()

Output:

Dept of CS & BS, KSSEM 20


DATA VISUALIZATION WITH PYTHON (BCS358D)

Program 4b:
Write a Python program to Demonstrate how to Draw a Scatter Plot using Matplotlib.

import matplotlib.pyplot as plt


import numpy as np

country = ['Brazil','Russia','India','China','South Africa']


per_capita_income = [9600, 11600, 10000, 11000, 6500]

# Plot the scatter plot


plt.scatter(country, per_capita_income, s=150, c='r', linewidth=1, marker='*', edgecolor='b')

#Add labels and title


plt.xlabel('Country')
plt.ylabel('Per_Capita_Income (USD)')
plt.title('Country vs Per Capita Income of BRICS Nations')

#Display the plot


plt.show()

Output:

Dept of CS & BS, KSSEM 21


DATA VISUALIZATION WITH PYTHON (BCS358D)

Program 5a:
Write a Python program to Demonstrate how to Draw a Histogram Plot using Matplotlib.

import matplotlib.pyplot as plt


import pandas as pd
import numpy as np
import random

#Generate random students marks


np.random.seed(42)
student_marks = np.random.normal(loc=70, scale=15, size=100)

#Create Histogram
plt.hist(student_marks, bins=20, color='skyblue', edgecolor='black')

#Add labels and title


plt.xlabel('Student Marks')
plt.ylabel('Frequency')
plt.title('Distribution of Student Marks')

#Display the plot


plt.show()

Output:

Dept of CS & BS, KSSEM 22


DATA VISUALIZATION WITH PYTHON (BCS358D)

Program 5b:
Write a Python program to Demonstrate how to Draw a Pie Chart using Matplotlib.

import matplotlib.pyplot as plt


import pandas as pd
import numpy as np

countries = ['Brazil','Germany','Italy','Argentina','Uruguay','France','England','Spain']
wins = [5, 4, 4, 3, 2, 2, 1, 1]
colors = ['yellow','magenta','green','blue','lightblue','red','cyan']

plt.pie(wins, labels=countries, autopct='%1.1f%%', colors=colors, startangle=90,


explode=[0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2], shadow=True)

#Add title
plt.title('FIFA World Cup Wins')

#Display the plot


plt.show()

Output:

Dept of CS & BS, KSSEM 23


DATA VISUALIZATION WITH PYTHON (BCS358D)

Program 6a:
Write a Python program to illustrate Linear Plotting using Matplotlib.

import matplotlib.pyplot as plt


import pandas as pd
import numpy as np

X = np.linspace(1, 20, 10)


print(X)
Y1=X

Y2 = np.square(X)
print(Y2)

Y3 = np.sqrt(X)

# Line plot
plt.plot(X, Y1, 'r', X, Y2, 'b', X, Y3, 'g')
plt.legend(['X', 'X-square', 'Square-root'])

# Add title to the plot


plt.title('Line Plot')
plt.grid()

# Display the plot


plt.show()

Output:

Dept of CS & BS, KSSEM 24


DATA VISUALIZATION WITH PYTHON (BCS358D)

Program 6b:
Write a Python program to illustrate liner plotting with line formatting using Matplotlib.
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

X = np.linspace(1,20,10)
print(X)

Y2 = np.square(X)
print(Y2)

# Line plot
plt.plot(X, Y2, marker='X', linestyle='dashed', color='red', linewidth=2, markerfacecolor='blue', markersize=8)

# Add title to the plot


plt.title('line plot')
plt.xlabel('Numbers')
plt.ylabel('Square Root')
plt.grid()

# Display the plot


plt.show()

Output:

Program 7:
Write a Python program which explains uses of customizing seaborn plots with Aesthetic functions.

import matplotlib.pyplot as plt


import numpy as np
Dept of CS & BS, KSSEM 25
DATA VISUALIZATION WITH PYTHON (BCS358D)

import seaborn as sns

def sinplot(n=10):
x=np.linspace(0,14,100)
for i in range(1,n+1):
plt.plot(x,np.sin(x+i*.5)*(n+2-i))

# To set the theme


sns.set()
sns.set_context("notebook",font_scale=1.5,rc={"lines.linewidth":2.5})

sinplot()
plt.title('Seaborn plots with Aesthetic Functions')
plt.show()

Output:

Dept of CS & BS, KSSEM 26


DATA VISUALIZATION WITH PYTHON (BCS358D)

Program 8a:
Write a Python program to explain working with bokeh line graph using Annotations and Legends.

from bokeh.plotting import figure, output_file, show


from bokeh.models import Legend, LegendItem, Title, Span

# Output to an HTML file


output_file("line_graph_with_annotations.html")

# Sample data
years = [1, 2, 3, 4, 5]
no_of_emp = [10, 40, 50, 30, 60]
sales = [20, 50, 70, 20, 80]

# Create a Bokeh figure


p = figure(title = "Line Graph with Annotations and Legends",
x_axis_label = 'Years', y_axis_label = 'No. of Employees/Sales')

# Add lines to the figure


line1 = p.line(years, no_of_emp, line_width=2, color="blue")
line2 = p.line(years, sales, line_width=2, color="green")

# Add annotations (vertical line and a text label)


annotation = Span(location=3, dimension='width', line_color='black', line_width=10)

# Add the annotation to the figure


p.add_layout(annotation)

# Create a legend
legend = Legend(items = [LegendItem(label = "No. of Employees", renderers = [line1]),
LegendItem(label = "Sales", renderers = [line2]),
])
p.add_layout(legend)

# Show the plot


show(p)

Output:

Dept of CS & BS, KSSEM 27


DATA VISUALIZATION WITH PYTHON (BCS358D)

Program 8b:
Write a Python program for plotting different types of plots using Bokeh.

#Line Graph
import numpy as np
from bokeh.plotting import figure, show

# Data
x = np.arange(0,10,1)
y1 = x ** 2
y2 = x ** 3
y3 = x ** 4

p = figure(title="Simple Line Charts", x_axis_label="x", y_axis_label="y")

p.line(x, y1, legend_label="Quadratic Function", line_width=2, color="red")


p.line(x, y2, legend_label="Cubic Function", line_width=2, color="green")
p.line(x, y3, legend_label="Quartic Function", line_width=2, color="blue")

show(p);

Output:

Dept of CS & BS, KSSEM 28


DATA VISUALIZATION WITH PYTHON (BCS358D)

#Bar Graph
import numpy as np
from bokeh.plotting import figure, show

# Data
x1 = [1, 2, 3, 4, 5]
y1 = [6, 7, 2, 4, 5]

p = figure(title="Bar Chart", x_axis_label="x", y_axis_label="y")

p.vbar(x=x1, top=y1, legend_label="Rate", width=0.5, bottom=0, color="blue")

show(p)

Output:

Dept of CS & BS, KSSEM 29


DATA VISUALIZATION WITH PYTHON (BCS358D)

#Scatter Plots
import numpy as np
from bokeh.plotting import figure, show

x = [1,2,3,4,5,6,7,8,9]
y = [9,8,7,6,5,4,3,2,1]

p = figure(title="Simple Scatter Plot", x_axis_label="x", y_axis_label="y")

p.circle(x, y, legend_label="Data Points", size=10, color="red")


#p.asterisk(x, y, legend_label="Data Points", size=10, color="red")

show(p);

Output:

Dept of CS & BS, KSSEM 30


DATA VISUALIZATION WITH PYTHON (BCS358D)

#Program 8
import numpy as np
from bokeh.plotting import figure, show, curdoc

curdoc().theme = "dark_minimal" # Current Document


#Other Themes: caliber, dark_minimal, light_minimal, night_sky, and contrast.

# Create a new plot object.


fig = figure(title='Different Types of Plots',
x_axis_label="X Axis", y_axis_label="Y Axis")

# Add data to the plot.


x = [1,2,3,4,5,6,7,8,9] # np.linspace(0, 10, 100)
y = [9,8,7,6,5,4,3,2,1] # np.sin(x)

# Add a line glyph to the plot.


fig.line(x, y, line_width=2, legend_label='Line Plot')

# Add a bar chart to the plot.


fig.vbar(x=x, top=y, legend_label='Bar Chart', width=0.1, bottom=0, color="green")

# Add a scatter plot to the plot.


fig.circle(x, y, size=10, color='red', legend_label='Scatter Plot')

# Changing figure properties after figure is drawn


fig.width=500
fig.height=300

# Customize the plot appearance.

Dept of CS & BS, KSSEM 31


DATA VISUALIZATION WITH PYTHON (BCS358D)

#fig.xaxis.axis_label = 'X Axis'


#fig.yaxis.axis_label = 'Y Axis'
#fig.legend.location = 'top_right'

# Show the plot.


show(fig)

Output:

Dept of CS & BS, KSSEM 32


DATA VISUALIZATION WITH PYTHON (BCS358D)

Program 9
Write a Python program to draw 3D Plots using Plotly Libraries.

# 3 D Scatter Plot
import pandas as pd
import plotly.express as px
import plotly.offline as pyo

pyo.init_notebook_mode()

size = [10, 20, 30, 40, 50]


x = [1, 2, 3, 4, 5] #[1, 2, 3, 4, 5]
y = [1, 2, 3, 4, 5] #[4, 5, 6, 7, 8]
z = [1, 2, 3, 4, 5] #[7, 8, 9, 10, 11]

# Creates Scatter Plot


fig = px.scatter_3d(x=x, y=y, z=z, size=size)

fig.show()

Output:

# 3D Line Plot
import pandas as pd
import plotly.express as px
import plotly.offline as pyo
pyo.init_notebook_mode()

# Create a data frame


df = px.data.tips()
Dept of CS & BS, KSSEM 33
DATA VISUALIZATION WITH PYTHON (BCS358D)

# View the contents of the data frame


print(df.head())
print(df.tail())
df = df[2:6]

# Create a 3D line plot


fig = px.line_3d(
df, # data
x="total_bill", # x axis
y="tip", # y axis
z="size", # z axis
color="day" # assign color to marks
)
# Set the line color
fig.update_traces(line_color=["red","green","orange","blue"])

# Display the plot


fig.show()
Output:
total_bill tip sex smoker day time size
0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3
2 21.01 3.50 Male No Sun Dinner 3
3 23.68 3.31 Male No Sun Dinner 2
4 24.59 3.61 Female No Sun Dinner 4

total_bill tip sex smoker day time size


239 29.03 5.92 Male No Sat Dinner 3
240 27.18 2.00 Female Yes Sat Dinner 2
241 22.67 2.00 Male Yes Sat Dinner 2
242 17.82 1.75 Male No Sat Dinner 2
243 18.78 3.00 Female No Thur Dinner 2

# Create a 3D scatter plot


Dept of CS & BS, KSSEM 34
DATA VISUALIZATION WITH PYTHON (BCS358D)

import pandas as pd
import plotly.express as px
import plotly.offline as pyo

pyo.init_notebook_mode()

# Create a data frame


df = px.data.tips()

# View the contents of the data frame


print(df.head())

print(df.tail())

df = df[2:6]
df

fig = px.scatter_3d(
df,
x="total_bill",
y="tip",
z="size",
color="day"
)

# Display the plot


fig.show()

Output:
total_bill tip sex smoker day time size
0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3
2 21.01 3.50 Male No Sun Dinner 3
3 23.68 3.31 Male No Sun Dinner 2
4 24.59 3.61 Female No Sun Dinner 4
total_bill tip sex smoker day time size
239 29.03 5.92 Male No Sat Dinner 3
240 27.18 2.00 Female Yes Sat Dinner 2
241 22.67 2.00 Male Yes Sat Dinner 2
242 17.82 1.75 Male No Sat Dinner 2
243 18.78 3.00 Female No Thur Dinner 2

Dept of CS & BS, KSSEM 35


DATA VISUALIZATION WITH PYTHON (BCS358D)

Dept of CS & BS, KSSEM 36


DATA VISUALIZATION WITH PYTHON (BCS358D)

Program 10:
Write a Python program to draw Time Series using Plotly Libraries.

import pandas as pd
import plotly.express as px

dollar_conv =
pd.read_csv("C:\\Users\\Lenovo\\Downloads\\CURRENCY_US_XTUP_USDINR_ONE_YEAR.csv")

#dollar_conv.head()
fig = px.line(dollar_conv, x='Date', y='Close', title='Dollar vs Rupee')

fig.show()

Output:

Program 10 b:
Write a Python program for creating Maps using Plotly Libraries.
import plotly.express as px
import pandas as pd

# Import data from GitHub


data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminder_with_codes.csv')

#data = pd.read_csv("C:\\Users\\Lenovo\\Downloads\\gap_minder_with_codes1.csv")
#data.head()

# Create basic choropleth map


fig = px.choropleth(data, # dataframe
locations='iso_alpha', #

Dept of CS & BS, KSSEM 37


DATA VISUALIZATION WITH PYTHON (BCS358D)

color='gdpPercap',
hover_name='country',
projection= 'natural earth', #'orthographic', # 'natural earth',
title='GDP per Capita by Country')

fig.show()

Output:

Dept of CS & BS, KSSEM 38


DATA VISUALIZATION WITH PYTHON (BCS358D)

VIVA QUESTIONS AND ANSWERS

1. What is Python?
Python is an interpreted scripting language that is known for its power, interactivity, and object-oriented nature.
It utilizes English keywords extensively and has a simpler syntax compared to many other programming languages.

2. Python is an interpreted language. Explain.


An interpreted programming language refers to any language that executes its instructions sequentially, one line
ata time. In the case of Python, programs are executed directly from the source code without the need for any
intermediate compilation process.

3. What distinguishes lists from tuples?

Lists Tuple
s
Lists are mutable, i.e., theycan Tuples possess immutability, denoting their
be
incapability of being modified like lists.
edited
Lists are usually slower Tuples are faster than lists
than tuples.
Lists consume a lot of Tuples consume less memory when compared to lists
memory

4. What are the Key features of Python?


The key features of Python are as follows: Interpreted, dynamically typed, Object-oriented programming, Cross
platform, General-purpose language.

5. How is Memory managed in Python?


Python makes use of automatic memory management through garbage collection. The garbage collector
keepstrack of objects and frees memory when they are no longer in use.

6. What are Python Modules?

Dept of CS & BS, KSSEM 39


DATA VISUALIZATION WITH PYTHON (BCS358D)

Files containing Python codes are referred to as Python modules. This code can be of different types
likeclasses, functions, or variables.

7. What is scope resolution?


In Python, a scope defines the region of code where an object remains valid and accessible. Every object in
Python operates within its designated scope.

8. What is a dictionary in Python?


Python supports various data types, including dictionaries. A dictionary in Pythonis a collection of elements
thatare stored as key-value pairs.

9. What are the applications of Python?


The applications of Python are as follows:
• GUI-based desktop applications
• Image processing applications
• Business and Enterprise applications
• Prototyping
• Web and web framework applications

10. What are the two major loop statements?


The two major loop statements in python are for and while.

11. What are functions in Python?


A function is a segment of code that runs only when it is called. The “def”keyword is utilized to define a
specific function.

12. What are the common built-in data types in Python?


Python supports the below-mentioned built-in data types:

Immutable data types: Number, String, Tuple

Mutable data types: List, Dictionary, Set

Dept of CS & BS, KSSEM 40


DATA VISUALIZATION WITH PYTHON (BCS358D)

13. What are local variables and global variables in Python?


A local variable is a variable that is defined within a specific function and is only accessible within that function.
It cannot be accessed by other functions within the program. A global variable is a variable that is declared outside
of any function, allowing it to be accessed by all functions in the program

14. What is type conversion in Python?


Python offers a valuable feature that allows for the conversion of data types as needed. This process is referred
toas type conversion in Python. Type conversion can be divided into two types:

Implicit Type Conversion: This type of conversion is automatically performed bythe Python interpreter without
requiring any user intervention.

Explicit Type Conversion: This type of conversion involves the user explicitly changing the data type to the
desired type.

15. What is the difference between Python Arrays and lists?


Arrays are data structures that hold fixed-size elements of the same type. Lists are versatile data structures that
canhold elements of different types and sizes.

16. Is python case sensitive?


Yes, Python is a case sensitive language. In Python, it is important to note that “Function” and “function” are
distinct entities.

17. Is indentation required in Python?


Indentation is an essential aspect of Python syntax, ensuring proper code structure. It is a method used by
programming languages to determine the scope and extentof code blocks.

18. How does break, continue, and pass work?

The following statements assist in altering the course of execution from the regularflow, which categorizes
themas loop control statements.

 Python break: This statement aids in discontinuing the loop or the statement and transferring control to
the subsequent statement.
Dept of CS & BS, KSSEM 41
DATA VISUALIZATION WITH PYTHON (BCS358D)

 Python continue: This statement enforces the execution of the subsequent iteration when a particular
condition is met, instead of terminating it.

 Python pass: This statement allows the syntactical writing of code while intending to bypass its execution.
It is also recognized as a null operation, as no action is taken when the pass statement is executed.

19. How to comment with multiple lines in Python?


To include a multiline comment in Python, each line should begin with the # symbol. This practice ensures that
the code is clear and easily understood.

20. What type of language is python? Programming or scripting?


Python is a versatile programming language that excels not only as a general- purpose language but also as a
scripting tool.

21. What are indexes and why are they used?


To retrieve an item from a sequential collection, we can simply utilize its index, which represents the position of
that specific item. Conventionally, the index commences at 0, implying that the initial element has an index of 0,
the second element has an index of 1, and so forth.

22. What split(), sub(), subn() functions perform in Python?


 split(): This method is used to split a given string into a list.

 sub(): This method is used to find a substring where a regex pattern matches, and then it replaces the
matched substring with a different string.
 subn(): This method is similar to the sub() method, but it returns the new string, along with the
number of replacements.

23. What do you mean by Python literals?


In programming, literals are used to represent specific values assigned to variables or constants. Python offers
various types of literals, including string literals, numeric literals, and boolean literals.

24. Do we need to declare variables with respective data types in Python?


No. Python is a dynamically typed language, i.e., the Python Interpreter automatically identifies the data type of a
variable based on the type of value assigned.

Dept of CS & BS, KSSEM 42


DATA VISUALIZATION WITH PYTHON (BCS358D)

25. What does len() do?


len() is an inbuilt function used to calculate the length of sequences like list, python string, and array.

26. How will you remove duplicate elements from a list?


To remove duplicate elements from the list we use the set () function.

27. What is the purpose of “is”, “not” and “in” operators?


Operators are referred to as special functions that take one or more values (operands) and produce a
corresponding result.

• is: returns the true value when both the operands are true (Example: “x”is ‘x’)

• not: returns the inverse of the boolean value based upon the operands(example:”1” returns
“0” and vice-versa.
• In: helps to check if the element is present in a given Sequence or not.

28. How can you generate random numbers in Python?


This is achieved by importing the random module. It is the module that is used togenerate random numbers.

29. How will you convert a string to all lowercase?


To convert a string to all lowercase in Python, you can use the built-in lower () method. The lower () method is
available for strings and returns a new string with all characters converted to lowercase.

30. What is the difference between append () and extend() methods?


Both append () and extend () methods are methods used to add elements at the end of a list.

The primary differentiation between the append () and extend () methods in Pythonis that append () is used to
adda single element to the end of a list. In contrast, open () is used to append multiple aspects, such as another
list or an iterable, to theend of a list.

31. What is slicing in Python?


Slicing is a technique employed to extract a specific range of elements from sequential data types, such as lists,
strings, and tuples. Slicing is beneficial and easy to extract out elements. It requires a : (colon) which separates the
start index and end index of the field.

Dept of CS & BS, KSSEM 43


DATA VISUALIZATION WITH PYTHON (BCS358D)

32. How do you create a Python function?


Functions are defined using the def statement.

33. What is data visualization in Python?


Data visualization in Python refers to the process of creating graphical representations of data using Python
programming language libraries such as Matplotlib, Seaborn, Plotly, etc. It allows for the exploration and
communication of patterns and relationships within the data.

34. What is Matplotlib?


Matplotlib is a Python plotting library that provides a wide range of 2D and 3D plots for visualizing data. It is widely
used for creating static, interactive, and animated visualizations in Python.

35. What is Seaborn?


Seaborn is a Python visualization library built on top of Matplotlib that provides a higher-level interface for creating
statistical graphics. It is used for creating visually appealing and informative statistical graphics such as heat maps,
pair plots, etc.

36. How do you install Matplotlib and Seaborn?


Matplotlib and Seaborn can be installed using pip, a Python package installer. To install Matplotlib, run "pip install
matplotlib" in the command line. To install Seaborn, run "pip install seaborn" in the command line.

37. How do you create a scatter plot in Matplotlib?


A scatter plot can be created in Matplotlib using the "scatter" function.

38. How do you create a line plot in Matplotlib?


A line plot can be created in Matplotlib using the "plot" function.

39. How do you customize the appearance of a plot in Matplotlib?


The appearance of a plot in Matplotlib can be customized using various functions such as "title", "xlabel", "ylabel",
"xlim", "ylim", "legend", "grid", etc.

Dept of CS & BS, KSSEM 44


DATA VISUALIZATION WITH PYTHON (BCS358D)

40. What is data visualization, and why is it important?


Data visualization is the representation of data in a graphical or pictorial format that makes it easy to understand
andinterpret. It is important because it allows analysts to see patterns, trends, and insights that may be difficult to
discern from raw data.

41. What are some common tools used for data visualization?
There are many tools available for data visualization, but some common ones include Python libraries like
Matplotlib, Seaborn, and Plotly, as well as tools like Tableau, PowerBI, and Excel.

42. How do you choose the best visualization for your data?

The best visualization for your data depends on the type of data you have, the question you are trying to answer,
andthe audience you are presenting to. Generally, simple visualizations like bar charts and scatter plots work
well for

43. What is Matplotlib?


Matplotlib is a Python plotting library that provides a wide range of 2D and 3D plots for visualizing data. It is widely
used for creating static, interactive, and animated visualizations in Python.

44. What is Seaborn?


Seaborn is a Python visualization library built on top of Matplotlib that provides a higher-level interface for creating
statistical graphics. It is used for creating visually appealing and informative statistical graphics such as heat maps,
pair plots, etc.

45. How do you install Matplotlib and Seaborn?


Matplotlib and Seaborn can be installed using pip, a Python package installer. To install Matplotlib, run "pip install
matplotlib" in the command line. To install Seaborn, run "pip install seaborn" in the command line.

46. How do you create a scatter plot in Matplotlib?


A scatter plot can be created in Matplotlib using the "scatter" function.

47. How do you create a line plot in Matplotlib?


A line plot can be created in Matplotlib using the "plot" function.

Dept of CS & BS, KSSEM 45


DATA VISUALIZATION WITH PYTHON (BCS358D)

48. How do you customize the appearance of a plot in Matplotlib?


The appearance of a plot in Matplotlib can be customized using various functions such as "title", "xlabel", "ylabel",
"xlim", "ylim", "legend", "grid", etc.

49. What is data visualization, and why is it important?


Data visualization is the representation of data in a graphical or pictorial format that makes it easy to understand
andinterpret. It is important because it allows analysts to see patterns, trends, and insights that may be difficult to
discern from raw data.

50. What are some common tools used for data visualization?
There are many tools available for data visualization, but some common ones include Python libraries like
Matplotlib, Seaborn, and Plotly, as well as tools like Tableau, PowerBI, and Excel.

51. How do you choose the best visualization for your data?
52. What is Matplotlib?
Matplotlib is a Python plotting library that provides a wide range of 2D and 3D plots for visualizing data. It is widely
used for creating static, interactive, and animated visualizations in Python.

53. What is Seaborn?


Seaborn is a Python visualization library built on top of Matplotlib that provides a higher-level interface for creating
statistical graphics. It is used for creating visually appealing and informative statistical graphics such as heat maps,
pair plots, etc.

54. How do you install Matplotlib and Seaborn?


Matplotlib and Seaborn can be installed using pip, a Python package installer. To install Matplotlib, run "pip install
matplotlib" in the command line. To install Seaborn, run "pip install seaborn" in the command line.

55. How do you create a scatter plot in Matplotlib?


A scatter plot can be created in Matplotlib using the "scatter" function.

56. How do you create a line plot in Matplotlib?


A line plot can be created in Matplotlib using the "plot" function.

Dept of CS & BS, KSSEM 46


DATA VISUALIZATION WITH PYTHON (BCS358D)

57. How do you customize the appearance of a plot in Matplotlib?


The appearance of a plot in Matplotlib can be customized using various functions such as "title", "xlabel", "ylabel",
"xlim", "ylim", "legend", "grid", etc.

58. What is data visualization, and why is it important?


Data visualization is the representation of data in a graphical or pictorial format that makes it easy to understand
andinterpret. It is important because it allows analysts to see patterns, trends, and insights that may be difficult to
discern from raw data.

59. What are some common tools used for data visualization?
There are many tools available for data visualization, but some common ones include Python libraries like
Matplotlib, Seaborn, and Plotly, as well as tools like Tableau, PowerBI, and Excel.

60. How do you choose the best visualization for your data?
61. What is Matplotlib?
Matplotlib is a Python plotting library that provides a wide range of 2D and 3D plots for visualizing data. It is widely
used for creating static, interactive, and animated visualizations in Python.

62. What is Seaborn?


Seaborn is a Python visualization library built on top of Matplotlib that provides a higher-level interface for creating
statistical graphics. It is used for creating visually appealing and informative statistical graphics such as heat maps,
pair plots, etc.

63. How do you install Matplotlib and Seaborn?


Matplotlib and Seaborn can be installed using pip, a Python package installer. To install Matplotlib, run "pip install
matplotlib" in the command line. To install Seaborn, run "pip install seaborn" in the command line.

64. How do you create a scatter plot in Matplotlib?


A scatter plot can be created in Matplotlib using the "scatter" function.

65. How do you create a line plot in Matplotlib?


A line plot can be created in Matplotlib using the "plot" function.

Dept of CS & BS, KSSEM 47


DATA VISUALIZATION WITH PYTHON (BCS358D)

66. How do you customize the appearance of a plot in Matplotlib?


The appearance of a plot in Matplotlib can be customized using various functions such as "title", "xlabel", "ylabel",
"xlim", "ylim", "legend", "grid", etc.

67. What is data visualization, and why is it important?


Data visualization is the representation of data in a graphical or pictorial format that makes it easy to understand
andinterpret. It is important because it allows analysts to see patterns, trends, and insights that may be difficult to
discern from raw data.

68. What are some common tools used for data visualization?
There are many tools available for data visualization, but some common ones include Python libraries like
Matplotlib, Seaborn, and Plotly, as well as tools like Tableau, PowerBI, and Excel.

69. How do you choose the best visualization for your data?
70. What is Matplotlib?
Matplotlib is a Python plotting library that provides a wide range of 2D and 3D plots for visualizing data. It is widely
used for creating static, interactive, and animated visualizations in Python.

71. What is Seaborn?


Seaborn is a Python visualization library built on top of Matplotlib that provides a higher-level interface for creating
statistical graphics. It is used for creating visually appealing and informative statistical graphics such as heat maps,
pair plots, etc.

72. How do you install Matplotlib and Seaborn?


Matplotlib and Seaborn can be installed using pip, a Python package installer. To install Matplotlib, run "pip install
matplotlib" in the command line. To install Seaborn, run "pip install seaborn" in the command line.

73. How do you create a scatter plot in Matplotlib?


A scatter plot can be created in Matplotlib using the "scatter" function.

74. How do you create a line plot in Matplotlib?


A line plot can be created in Matplotlib using the "plot" function.

Dept of CS & BS, KSSEM 48


DATA VISUALIZATION WITH PYTHON (BCS358D)

75. How do you customize the appearance of a plot in Matplotlib?


The appearance of a plot in Matplotlib can be customized using various functions such as "title", "xlabel", "ylabel",
"xlim", "ylim", "legend", "grid", etc.

76. What is data visualization, and why is it important?


Data visualization is the representation of data in a graphical or pictorial format that makes it easy to understand
andinterpret. It is important because it allows analysts to see patterns, trends, and insights that may be difficult to
discern from raw data.

77. What are some common tools used for data visualization?
There are many tools available for data visualization, but some common ones include Python libraries like
Matplotlib, Seaborn, and Plotly, as well as tools like Tableau, PowerBI, and Excel.

78. How do you choose the best visualization for your data?
The best visualization for your data depends on the type of data you have, the question you are trying to answer,
andthe audience you are presenting to. Generally, simple visualizations like bar charts and scatter plots work
well for

basic analysis, while more complex visualizations like heat maps and network graphs are better for advanced
analysis.

79. What is the difference between a histogram and a bar chart?


A histogram is used to represent the distribution of continuous numerical data, while a bar chart is used to compare
categorical or discrete data.

80. How do you create a scatter plot in Python?


A scatter plot can be created in Python using libraries like Matplotlib or Seaborn. It is typically created using two
variables, one for the x-axis and one for the y-axis. The "scatter" function in Matplotlib or Seaborn can be used to
create a scatter plot.

81. How do you decide whether to use a bar chart or a line chart?
A bar chart is used to compare categorical or discrete data, while a line chart is used to show trends or changes
overtime. When deciding which to use, consider the type of data you have and the question you are trying to
answer.

Dept of CS & BS, KSSEM 49


DATA VISUALIZATION WITH PYTHON (BCS358D)

82. Can you differentiate between Matplotlib and Seaborn?

Matplotlib and Seaborn are both Python libraries used for data visualization, but they differ in their functionalities
and use-cases. Matplotlib is a low-level library providing extensive control over every aspect of a plot, making it
suitable for creating custom plots.

Seaborn is built on top of Matplotlib, offering a high-level interface for drawing attractive statistical graphics. It
simplifies tasks such as generating complex visualizations of multi-dimensional data and provides built-in themes
for styling matplotlib graphics.

83. What are Pandas?


Pandas is an open-source python library that has a very rich set of data structures for data-based operations. Pandas
with their cool features fit in every role of data operation, whether it be academics or solving complex business
problems. Pandas can deal with a large variety of files and are one of the most important tools to have a grip on

84. Explain Bokeh?


Bokeh is a data visualization library in Python that provides high-performance interactive charts and plots. Bokeh
output can be obtained in various mediums like notebook, html and server.

85. What is Plotly?

Plotly is a graphing library for creating interactive, publication-quality graphs online.

Dept of CS & BS, KSSEM 50


DATA VISUALIZATION WITH PYTHON (BCS358D)

Dept of CS & BS, KSSEM 51

You might also like