DXE 24gksmknvj
DXE 24gksmknvj
2. Section A is compulsory.
3. Attempt any four questions from Section B.
4. All the parts of a question must be answered together.
5. Assume that numpy has been imported as np and
pandas has been imported as pd.
P.T.0.
4270 2
Section A
on the execution
1. (a) What will be the output produced
(2)
of the following code?
56.9,29.4,-72.7])
narr = np.array ([-4.6, 8.2, 14.5,
narrl = narr.astype (np. int32)
print (narr1)
a column EmpId.
(b) Consider a DataFrame dfl with
rows
Write a Python statement to remove
containing duplicate Empld values from
dfl and
combination.
keep oniy the last observed value
(2)
below:
(c) (i) Plot the graph generated by the code
(2)
(i) arr_x.dtype
(iii) 1/arr_ y
(i) reindex()
(i) arange()
P.T.0.
4270 4
(h)
data = pd. DataFrame ({
(4)
'Dept': ['X', X', Y', 'Y',
'Age': [19, 21, 23, 21, 20],
' Category': ['I', 'II', ' I , II',
Salary': [1800, 2100, 2000, 2200, 1100]
})
Section B
P.T.0.
4270 6
Col1 Col2
B23 52
A 43 89
C 12 86
serl ser2
A 3 A 9
B 2 B 8
C 1 D 6
D 4 7
()) serl.values
(ii) ser2.index
(ii) ser2[:3] * 5
(v) ser2|: :
P.T.0.
8
4270
represented in Pandas?
(b) How are missing values
detected.
Explain how the missing values are
Pandas.
removed and replaced using functions in
(6)
salesman
(c) Consider the year-wise sales made by a
89,
in the last ten years for product A: [80, 92, 88,
100, 70, 78, 88, 80, 34] and product B: [35, 76, 35,
88, 100, 48, 79, 88, 65, 35]. Write Python
statements to
First Second
C OneC Two C OneCTwo
0 W 0 X
2 X 1 7
3
U
6 7 2 W
P.T.0.
4270 10
() print (data.T)
print(data)
rent = [20, 12.5, 35, 47.5, 56, 22, 17.5, 31, 28, 40]
df = pd. DataFrame ({
' category': ['A' 'B "B', "A'],
type: ['X', "Y', Z'
value': np.arange (10, 20, 2)
})
(i) print(df)
T
4270 12
students
(b) Consider the following data about five
enrolled in a course: (7.5)
2101 CS 18 87
2102 CS 19 45
2103 CS 19 69
3101 Stats 20 91
3102 Stats 21 56
5
0.5
4
0.0 3
-0.5 2
2 3 4
12.5 1.0
10.0 0.8
7.5
0.6
5.0
0.4
2.5 0.2
0.0 0.0
0.0 0.2 0.4 0.6 0.3 I.0
P.T.0,
4270 14
following
(b) Consider the file data.csv with the
contents : (8)
1,2, 3, 4, hello
5, 6, 7, 8, world
9, 10, 11,12, foo
the
(i) Write a Python statement to read
the
above file into a DataFrame data with
last column (hello, world, and foo)
constituting the index.
data.
(ii) List the contents of DataFrame
the
(iii) Write a Python statement to store
DataFrame data in the file updated data.csv
using colon (:) as the separator.
'Amazon']
execution
produced on the
(b) What will be the output (10)
of the following code?
.reshape (4, 4)
np.arange (16)
(1) a=
print (a)
a[(a 7) ] = -1
print (a)
1]])
([ [4, 3], [2,
np.array
(ii) x = zeroes like (x)
y = np.
print (y)
Z= np.eye (4) * X
print (z)
P.T.0.
4270 16
Y!
(iv) obj1 = pd. Series (['X',"three',
A' B'],
index=['one ' , 'two', 'five' ])
print (obj1)
print (obj1 ['three':'five'])
(500)