[This question paper contains 8 printed pages]
Your Roll No. :
Sl. No. of Q. Paper : 7743 I
Unique Paper Code : 2342202102
Name of the Paper : B. A. (P) NEP
Name of the Course : Data Interpretation and
Visualization Using
Python
Semester : II
Time: 3 Hours Maximum Marks: 90
Instructions for Candidates:
(a) Write your Roll No. on the top immediately on
receipt of this question paper.
(b) Section-A is compulsory.
(c) Attempt any four questions from
Section-B.
(d) Parts of a questions must be answered together.
Assume numpy has been imported as np and pandas
has been imported as pd.
Section -A
(Compulsory)
1.
(a) What is the purpose of the describe () function in
Pandas? Illustrate with one example. 2
(b) Consider a dataset with a mean of 50 and a standard
deviation of 10. Compute the Z - score for a data
point 65. 2
P.T.O.
कालिन्दी महाविद्यालय पुस्तकालय
KALINDI COLLEGE LIBRARY
7743
(c) What are the two advantag
es of NumPy that makes
it important for numerical comput
ation in Python ?
2
(d) Give the following array : 2
arr = [Link] ([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
Write Python code to print the sub array [[2, 3],
[5, 6]]
-
(e) Differentiate between Experiment and
Observational studies. 2
(f) Give a Series s:
s = [Link] ([100, 200, 300], index = [0, 2, 4)]
Write output of the following Python statements :
(i) s1 = [Link] ([0, 1, 3, 4], method = 'ffill')
print (sl)
(ii) s2 [Link] ([0, 1, 2, 3, 4], method
= = 'bfill')
print (s2)
(g) Write Python code to do the following : 3
(i) Read a file named "students. csv" into a
DataFrame df.
(ii) Display the first 5 rows of the DataFrame df.
(iii) Save the DataFrame df to a new file
"top_students.csv" using '+' as a separator.
(h) Write Python command to create the following
Series with hierarchical index levels 'Group' and
'Number'. 3
Group Number
A 1 10
2 20
B 1 30
2 40
कालिन्दी महाविद्यालय पुस्तकालय
KALINDI COLLEG
E LIBRARY
7743
(i) Given the following DataFrame : 3
df = [Link] ({
'Team': ['A', 'B', 'A', 'B', 'A', 'B'],
'Points': [10, 20, 15, 25, 10, 30]
'Assists': [1, 3, 2, 4, 1, 5]
})
Write Python code to perform the followin
g
operations :
(i) Group the data by "Team" and compute the
total 'Points' per team.
(ii) Compute the average 'Assists' per team.
(j) What is the difference between Ser
ies and
DataFrame in pandas ? Explain with the
help of an
example of each. 4
(k) Write Python code to plot a horizontal bar char
t using
matplotlib for the following data: 4
Subjects = ['Math', 'Science', English', 'History']
Scores = [88, 75, 92, 70]
Label the x - axis as 'Scores' and y axis as
'Subjects' and add a title 'Student Scores by 'Subject'.
-
Section - B
2. (a) Give an array scores : 4
scores [Link] ([45, 67, 89, 32, 76, 54, 90, 38,
= 50](
Write Python code for the following :
(i) Print scores greater than 50.
(ii) Print scores that are even numbers.
(iii) Reshape the arry scores into a 2-dimensional
array scores_2 D of shape 3×3.
(iv) Convert the data type of scores_2D to np. float
64.
3 P.T.O.
कालिन्दी महाविद्यालय पुस्तकालय
KALINDI COLLEGE LIBR
ARY
7743
(b) Given the following DataFrame : 5
data = [Link] ({
'Department': ['HR', 'IT", 'HR', 'IT', 'HR', 'IT'],
'Gender': ['M', 'F', 'M', 'M', 'M', 'F']
'Salary': [50000, 60000, 52000, 58000, 51000, 5500o[
})
Write Python code to perform the following
operations:
(i) Create pivot table that shows the average
a
salary for each department.
(ii) Create a pivot table to display average salary
by both department and gender.
(iii) Modify the code in part (ii) to fill missing
values in the pivot table with 0.
(c) Define mean, median, and mode. 6
Give the following dataset :
data = [12, 15, 12, 18, 19, 15, 15, 20, 25]
Calculate the mean, median, and mode of the data.
3. (a) Differentiae between stack () and unstack
() methods with the help of examples. 4
(b) Write Phython code to create a 2 D NumPy array of
shape 3×3 filled with random integers between 5
and 15 (both inclusive) and then print its dimension,
shape and transpose. 5
(c) Write the output of the following Python code: 6
dfl = [Link] ({'Math': 80, 901], 'English': [70, 61]},
index = ['Alice', 'Bob'])
df 2 [Link] ({'English': [85, 75], 'Science':
=
[88, 92]}
4
कालिन्दी महाविद्यालय पुस्तकालय
KALINDI COLLEGE LIBRARY
7743
index = ["Bob", "Charile"])
result 1 = dfl + df2
result 2 = [Link] (df2, fill_value = 0)
print ("Result 1 :\n", resultl)
prit ("\nResult2 : \n", result 2)
4. (a) Differentiate between descriptive statistics and
5
inferential statistics with examples.
(b) Given the DataFrame marks :
marks = [Link] ({
"Math": [78, 85, [Link], 88, 74]
"Science" [82, [Link], 95, 91, 76],
:
"English" : [75, 80, 88, [Link], 70]
}, index = [Amit', 'Rina', 'John', 'Meera', 'Raj'])
Write Python code to do the following:
(i) Compute the average marks for each student (row
-wise), ignoring missing values.
(ii) Identify the name of the student with the highest
average marks.
(iii) Print only those students whose average marks
(from part a) are greater than 80.
(iv) Count the total number of missing values in the
DataFrame.
(v) Fill all missing values in the DataFrame with
'Absent'.
5
5. (a) Give an array arr :
arr = [Link] ([10, 20, 30, 40, 60, 70])
5 P.T.O.
कालिन्दी महाविद्यालय पुस्तकालय
KALINDI COLLEGE LIBRARY
7743
Write Python co
de for the following :
(i) Create slic
elements fro e s_arr
a
m index 2
of arr and assign
to 4.
(ii) Assign a new value (999)
the s_arr. to all elements in
What will be
the contents
of s_arr and
above code is execut arr after th
ed ? e
(b) Write the output of the following Py
thon code : 10
dfl [Link] ({
=
'Employee ID': [101, 102, 103,
104],
'Name': ['Alice', 'Bob', 'Charl
ie', 'David'],
'dept': ['HR' 'IT', 'Finance', 'Marketing']
})
df 2 = [Link] ({
'Employee ID' : [102, 103, 105],
'Salary': [60000, 75000, 50000],
'Bonus': [5000, 7000, 400o[
}}
m1 = [Link] (df1, df2, how = 'inner')
m2 = [Link] (df1, df2, how = 'left')
m3 = [Link] (df1, df2, how = 'right')
m4 = [Link] (df1, df2, how = 'other')
print (m1)
print (m2)
print (m3)
print (m4)
न् दी मह ाव िद ्य ाल य पुस्तकालय
का लि EGE LIBRARY
L
KALINDI COL
7743
6. (a) Give a dictionary data : 4
data = {
'Name': [Amit', 'Rina', 'John', 'Meera', Raj'],
'Age': [21, 23, 25, 22, 24],
'Score': [45, 78, 49, 88, 35]
Write Python code to perform the following operations:
(i) Create a DataFrame df from data.
(ii) Print all rows of DataFrame df where Age
22.
(iii) Add a column 'Grade' with values
new ['A',
'B', 'A', 'C', 'D'] in df.
(iv) Delete the column 'Score' from df.
(b) Explain how missing data is represented in Pandas.
With the help of suitable examples, show the use of
isnull (), notnull (), dropna (), and fillna () functions
in handling missing data. 5
(c) Write the output of the following Python code : 6
I = [Link] (4, dtype = int)
print (I)
diag = I [[0, 1, 2, 3], [0, 1, 2, 3]]
prit (diag)
I [[0, 1, 2, 3], [0, 1, 2, 3]] + = 5
print (I [[1, 3]])
7. (a) Given a Series of exam scores : 5
scores = [Link] ([45, 67, 89, 52, 76, 90, 33, 84,
59, 100])
Write Python code to :
7 P.T.O.
कालिन्दी महाविद्यालय पुस्तकालय
KALINDI COLLEGE LIBRARY
7743
(i) Discretize the scores into bins: 'Poor' (0-50),
'Average' (51-70), 'Good' (71-85) and
'Excellent' (86-100).
(ii) Display the frequency count of each bin.
(iii) Divide the scores into 4 equal - sized groups
(quartiles).
(b) Write Python code to create a figure with two
subplots arranged in a single row using matplotlib.
10
(i) Generate a blue coloured line plot of the
square of numbers from 1 to 5 in the first
subplot. Use a dashed line style ('-') and set
the title as 'Line Plot of x^2'.
Set x-axis label as 'x' and y-axis label as 'x^2'.
Add custom x-tick lables as
['one', 'two', 'three', 'four', 'five'].
(ii) General a scatter plot of the same data in
the second subplot. Use green coloured circle
marker ('o') and set the title as 'Scatter plot
of x 2'. Set x-axis label as 'x' and y-axis lable
as 'x^2". Add custom y-tick labels as
['1 ^ 2', '2 ^ 2', '3 ^ 2', '4 ^ 2', '5 ^ 2'].
***
8 500
कालिन्दी महाविद्यालय पुस्तकालय
KALINDI COLLEGE LIBRARY