0 ratings0% found this document useful (0 votes) 68 views16 pagesGE Python Visualization 2023
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
[This question paper contains 16 printed pages.]
Sr. No. of Question Paper :
Unique Paper Code
Name of the Paper
Name of the Course
Semester
Duration : 3 Hours
Your Roll No...
2012 F
2344001201
Data Analysis and Visualization
Using Python
Computer Science: Generic
Elective (G.E.)
Il
Maximum Marks : 90
Instructions for Candidates
1 Write your Roll No. on the top immediately on receipt
of this question paper.
2. This question paper has two sections A and B.
3. Question 1 in Section A is compulsory.
4. Attempt any 4 questions from Section B.
5. Parts of a question must be attempted together.
6. Section A carries 30 marks and each question in
Section B carries 15 marks.
7. Use of Calculator is not allowed.
PTO2012 2
Section A
Assume numpy has been imported as np and pandas
has been imported as pd.
(a) Explain unimodal, bimodal and multimodal
distribution with the help of examples. (5)
(b) Consider the DataFrames First and Second given
below : 6)
Cc One Two One Two
0 'A'
2 “Be
5 ™D?
6 Ter
First Second
Consider the following python code segment :
right = pd.merge(first, second, how="right’, on='One')
left = pd.merge(first, second, how='inner’, on="Two')
Show the content of the new DataFrames right
and left.2012 3
(c) Write python commands to create a figure object
using matplotlib. The Figure object has one subplot
that contains 3 line graphs. Define legend and chart
title of the graph. Define a different style and
for each line in the subplot. Import
(5)
colour
appropriate libraries.
(d) List and describe the steps involved in process of
Data Analysis. (5)
(e) Give the output of the following code snippets:
(4)
(i) y=np. arange(12).reshape(4,3)
print(y)
yl(y > 5)] = -1
print(y)
(ii) x = np.array ([[2, 4], [5,1])
z=np.ones_like(x)
print(z)
w=np.eye(2) * x
print(w)
P.T.O.2012 4
(f) Consider the series S1 and $2 given below : (
6)
SI $2
A I A 5
Bee B 6
Cc 3 D 7
_ _
Give the output of the following python pandas
commands :
(i) S1[: 3] * 10
(ii) S1 + S2
Gi) 2522 (cS.
Section B
2. (a) Consider the DataFrame Frame given below: (7)
Age Weight
15 45.6
23 34.9
32 45.6
20 60.7
$4.7 110
21 34.6 1442012 5
Write python commands to perform the following
operations
Q) Compute the correlation of Age with both
Weight and Height.
(a) Sort Frame in descending order of Age.
(ii) To find the index for the row with minimum
Age.
(iv) Calculate cumulative sum for Weight for
all Students.
(v) To set height of ‘Rita’ and ‘Romi’ to
NA.
(vi) Replace the value 32 with 18 and 33 with
19 in Age column.
(vii) Define map function to convert values of
Name column to upper case.6
2012
(b) Refer to the DataFrame Frame given in question
2 (a), Write a python program to Perform th
- . ie
following operations in the given dataset with
columns Name, Age, Weight, Height, (8)
(i) Create a figure and include 2 subplots in
it.
(ii) In the first subplot create a Scatter
plot between two variables Age and
Height.
(iii) In the second subplot draw a horizontal
bar plot between Name and Weight.
(iv) Set the title for the figure as ‘Data
Analysis’.
(v) Give appropriate labels for x and y axis.
(vi) Save the figure to file with name
‘analysis.png’.2012 7
3. (a) Consider the following numpy array matrix :
(10)
[[5,10,20],
[20,13,43],
(34,27,67],
[12,46,77]]
Give the output of the following numpy commands :
(i) matrix.T
(ii) matrix[:1,1:]
(iii), matrix[[1,3,0],[2,1,0]]
(iv) matrix[[-2,-4]]
(v) matrix[[True, False, False, True]]
(vi) matrix(3] [:2]
(vii) matrix[::—1]
P.T.O.2012 8
(vi) mater ndim
ax) np swaparxescmatrix, b, 0)
(x) matrix? 10
Consider the to
lowing DataPrame df.
ve commands to perform the following operations:
|) List the name of unique items sold.
ch value 1"
(4) Count the number of tim
items is stored.
- duplicate2012 9
(iv) Give the average price of all Low Fat
items.
(v) Check if ‘Juice’ ims one of the items
sold.
4. (a) Consider the DataFrame data given below. (4)
One Two | Three | Four | Five
1 14 34 NaN NaN
34 21 NaN 12 NaN
NaN 23 NaN 2 NaN
34 21 32 33 NaN
Write python commands to perform the following
operations :
(i) Drop columns with any null values.
(ii) Replace the null values with the mean of
each column.
(iii) Drop the null values where there are at
least 2 null values in a row.10
2012
Ye value :
diy Replace all null VAIUES BY the 1381 Knog
valid observation
What arc outers? How can you detect Outliers
using boxplots? (5)
Consider the given numpy array mat: (6)
np.array([[[-1,2], (3,4]], [[-5,6], [7,8]]))
Write numpy commands to perform the following
ations
()) Create an array of zeros with the same
shape as mat.
ul) Print the shape of the mat.
(ui) Print the datatype of the elements in mat
. 4 an
(iv) Print the elements which are grealet th,
6 in mat.
at as float
(v) Convert all the elements in mat
type.11
2012
(vi) Multiply each element in mat with 25.
(a) Give the python commands to create
with 5 keys — ‘A’, ©
a dictionary
7D’, ‘BE and value as
(10)
follows.
|
Key Value
A | Listof numbers from 1 to 10 skipping 2 ata time.
| List of Strings from A to E-
c | List of 5 numbers obtained using random normal
distribution function.
List of 5 random integers from 20 to 30.
mo
Square root of 5 random numbers from 50 to 70.
Give python commands to perform the following
operations :
(i) Create DataFrame data using the above
dictionary.
(ii) Convert Column A to index.
(iii) Rename the rest of the columns as Area,
Temperature, Latitude and Longitude.
P.T.O.12
2012
(iv) Delete the column Longitude from dat
a
(vy) Save data as a csv with separator as to
(b) Write a python code to create a figure and :
subplot using matplotlib functions. Plot a Tectangle
of size 3.5 x 8.5 at point (2.0, 7.0), a circle of
radius 2.5 at point (7.0, 2.0) as patches in the
subplot, functions for plotting. Set the colour of
rectangle as ‘Green’ and color of circle as ‘Blue’,
Set the x-scale and y-scale to 1-10. Import
appropriate libraries. (5)
(2) Consider the following dataset student. (10)
Year | Name | Roll No | Marks Age
i] Rani 23 70 18
2) Rita 24 75 20
3 Raj 25 80 22
1 [Rahul Gi 65 25
2 | Rohit 27 30 | 28 J
, ds
Give the output of the following python comman
(i) student [['Roll No ',' Name'] [2:4]2012 13
(ii) student [student ['Age'] *20]
(iii) student [student ['Age'] *20] ['Name']
(iv) avg marks np.mean (student.Marks)
student[student['Marks'|>avg_marks]
(v) first = student [student ['Year'] ==1][{'Marks']
np.mean(first)
(b) Consider the following list 11. (5)
11 = [10, 10, 20, 40, 50, 60, 70, 80, 90, 90]
Discretise the 11 into 4 bins using cut() and qcut().
Give the names [‘first’, ‘second’, ‘third’, ‘fourth’]
to the bins. What type of object is returned by the
pandas after binning? What output is generated
by attributes codes and categories of binning
object?
DTNn2012 -
7. (a) Consider the DataFrame df given below : (8)
| EmployeeID | Department | Salary |
M001 English 1000
T00° English — i.
003 English hh
Pood English 1005.
1003 _| Maths | 1004
[0.04 eee es Mat io vaeeeem 1005
1001 Maths 1006
a Maths 1002
Write the python code to perform the following
operations :
4) Create a hierarchical index on Department
and Employee ID.
(1) Give the summary level statistics for each
column.
(i) Give the output for the following :
1. df.stack()
2. df.unstack()2012 15
(b) Give the output of the following code segment
. nt:
(4)
arr ~ np.array([89, 54, 76, 32, 47, 21, 92, 39, 82])
arrl = arr[5:9]
arr2 = arr[5:9].copy()
arrl = 36
arr2 = 7
print(arr)
print(arrl)
print(arr2)
(c) Consider the series a given below and give the
output of the following commands : (GB)
a = pd.Series([4, I, 7,1, 8,9, 0,8, 2,3, 9)
(i) a.rank()
P.T.O.2012 16
(ii) a.rank(method “first’)
(iii) a.rank(ascending False)