Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

2 1461

1461
as np arr2
import numpy
[3,4,2]]. (14,6,5]. [3,1,6]11)
a=np.array(ll[1,2,3], print
b-np.random.randn(4,3)
(e) Expl=
print(a.shape)
print(b.shape)
() Expl
that can be used read
(b) Explain any two functions
with suitable
to create numpy array objects, (g) Expl
examples. (4)
objec
(c) Consider the given pandas series object and write
(h) Writ
the output of the following code statements (5)
Pythe
import pandas as pd
(i) Writ
obj2=pd.Series([4, 6, 5, 8, 7],index-['d', b', 'c',
'a', 'e]) impo
() print (obj2[*d'] ) df =
(ii) print (obj2 [obj2>5])
(ii) print (obj2.index)
(iv) print (obj2*3) print1
(v) print (obj2['b':'a'])

d) Write the output of


the following code: (2)
import numpy as np
arr = np.array ([3.7, -1.2, 2 (a) Write
-2.6, 0.5, 12.9, 10.1])
1461 3

arr2 = arr. astype(np.int32)


print(arr2)

(e) Explain reindex() function for a series object.


(2)
() Explain skiprows and na values attributes of the
used read csv) function. (3)
itable
(4)
(g) Explain bool and string data types of ndarray
object. (4)
d write
s: (5) (h) Write a short note on matplotlib library in
Python. (3)

b', e, () Write output of the following code:


(4)
import pandas as pd
df
pd.DataFrame(f'Animal':'Falcon', 'Falcon',
'Parrot', 'Parrot'],
'Max Speed': [380., 370., 24., 26.]})

print(df.groupby(['Animal').mean()
(2)
Section B
.9, 10.1) 2. (a)
Write output of the
following code: (6)

P.T.O.
1461 4
1461
import pandas as pd

dl = (Name': (Pankaj', 'Meghna', 'Lisa'],


"ID': [1, 2, 3],

Country': ['India', 'India', 'USA], (c) Giv

'Role': ['CEO", 'CTO', 'CTO'} imp


dfl = pd.DataFrame(dl) imp
df2 = data
pd.DataFrame({'ID': [1, 2, 3],
Name': [(Pankaj', 'Anupam', 'Amit']}) inde
'fou
print(dfl.merge(df2, on=ID))
print(dfl .merge(df2, on=Name')) Writ

print (dfl .merge(df2, how='left')

(b) Differentiate between loc and iloc


suitable examples. operators giving
(4)
(c) Write code in
python to create a pandas series
object of all even numbers from 2 to 30,
2 and 30, using including
3.
arange). (5)
(a)
Explain hierarchical indexing in dataframes.
(b) Write the (4)

code for cachnamesin of functions and give example


matplotlib : (6)
1461 5

(i) for setting tick labels on xX axes

(ii) for adding legend to a plot

(c) Given the code below (5)

import numpy as np
import pandas as pd
data = pd.DataFrame(np.arange(12). reshape(3, 4),
index=['A', 'B', 'C], columns=['one', 'two', 'three',
Amjs 'four'])
Write the output for following :

() print(data)

(ii) print(data.sum)
rS giving (ii) print (data.sum(axis= 'columns'))
(49)
(iv) print (data.idxmax()
das series (v) print (data.cumsum())
including 4.
(5) (a) Explain the functions used for : (5)

mes, () Removing duplicates in a dataframe


(4) (ii) Filling missing entries in a dataframe
e example (b) Explain how to create subplots using matplotlib,
(6 with suitable example. (5)

P.T.O.
1461 7

year;qtrl;qtr2;qtr3;qtr4
2019;3000;3200;;3500
2020;2900;-9999;;

2021;1800;2 100;1900;1950
2021;1800;2 100;1900;1950
2022;1850;-9999;2900;2550
2023;3400;3200;;

(i)) Load the file sales.csv into a dataframe.

(ii) Fill all the NaN values with 0.


rows from the
(iii) Remove the duplicate
original dataframe.

Replace all the -9999 values with a 0.


(iv)

the average sales made during qtrl


(V) Print
across all the years

horizontal and
to plot a
(a) Write Python statements assumed dataset. (5)
any
Vertical bar chart of
following
the
5) statements to do (10)
(b) Write the Python
nd
using matplotlib package : PTO.
(5)
8
1461 colours of 7
histogram of different
() Plot your city.
days temperature of
Days Temperature".
(i) Set title as "7
X-axis "Weekdays"
(iii) Set label for
"Temperature"
(iv) Set label for Y-axis
(v) Save the image as "temp-pick.jpg"

plots,
7 (a) Write short note on histograms and density
with suitable examples. (4)

(b) Explain the functions : (8)


() value counts)
(i) stack()
(i) barh()
(iv) arange)

(c) Write output of the following code: (3)


import pandas as pd
ages-[15, 47, 56, 23, 78, 90]
bins-[12, 30, 70, 95]
categories = pd.cut(ages, bins)
print(categories)

(1000)
1461
6
1461 functions in pandas
dropna
fillna and (5)
(ey Explain example code.
dataframes, with
write
given dataframe df and
Consider the following
5. (a) statements to perform the
the Python (5)
operations:

ID marks
B23 52
A34 67

c25 60
as name
(i) Set the title of the row index
2,1,2
(i) Add a column 'semester with values
(ii) Sort the dataframe in descending order of
the marks columnn.

(iv) Reindex the dataframe in the order A, B


and C.

(v) Drop the row corresponding to row index


C
. (a)W
ve
b) Explain covariance and correlation with suitable
examples. (5) (b) W
(c) Consider the fde sales.csv as given below and
answer the following questions. (5)

You might also like