0% found this document useful (0 votes)
50 views6 pages

Your Roll No ..............

Uploaded by

somya.234017
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)
50 views6 pages

Your Roll No ..............

Uploaded by

somya.234017
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/ 6

5482-A 12 [This question paper contains 12 printed pages.

Your Roll No ...............


(b)Given a DataFrame df with a column
`Temperature' representing the temperature
Sr. No. of Question paper : 5482-A H
readings in celsius: (5)

Unique paper code : 2342201202


df = pd.DataFrame({`Temperature': [25.5, 30.2,
18.9, 22.I, 27.8, 31.5, 20.3, 24.7, 28.6, 26.4]})
Name of the Paper : Data Interpretation and
Visualization Using Python
(i) Divide the temperature into bins of 5
degrees [15, 20, 25, 30, 35] using the
Name of the Course : B.A. 0') NEP
pd.cut() function. Name the bins as [`very
low', `1ow', `high', `very high'].
Semester : 11

(ii) What is the purpose of passing iight=False Maximum Marks : 90


Duration : 3 Hours
in pd.cut() function?

(iii) Count the number of readings in each / Instructions for Candidates


temperature bin.

1. Write your Roll No. on the top immediately onreceipt


(iv) Which function will be used to divide the
of this question paper.
temperature into four bins having the same
number of readings?
2. Section A is compulsory.

(c) Define the following along with Python functions 3. Attempt any four questions from Section 8.
to create them : (6)
4. Parts of a question must be answered together.
(i) Histogram
Assume numpy has been imported as np and pandas
(ii) Density plots
has been imported as pd.
(iii) Heatmap

P.T.O.
(500)
5482-A 2 5482-A 11

Section - A (b) How can subplots be created using Matplotlib?


Provide an example of creating a 2x2 figure with
(Compulsory)
four subplots - bar plot, horizontal bar plot, line
plot, and scatter plot. (6)
1. (a) Write the output of the following code snippet:

(2) (c) Differentiate between experiment and observational


s = pd.Series([1,I, 2, 2, 3])
study. (4)

print(s.unique()) In a Randomized Controlled Trial (RCT), eligible

print(s.value_counts()) people are randomly assigned to one of two or


more groups. One group receives the intervention

(b) Write the output of the following Python code: (such as a new drug) while the control group
receives nothing or an inactive placebo. The
(2)
a = np.array([[l, 2, 3], [4, 5, 6]]) researchers then study what happens to people in
each group.
print(a.ndim) +\
What kind of study is RCT - experiment or
print(a.shape) observational study? Give reason.

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


7. (a)Givenaseriess:
(2) (4)
df = pd.DataFrame({`A':[l, 2, 3], `8':[4, 5, 6]}, s = pd.Series([4,5,3,4,2,1,1])

index=(`X','Y','Z')) Write Python statements to perform the following

print(df.iloc[1]) Operations :

print(df,loc[`X']) (i) Using the replace() function, update s by


replacing the value 4 with np.nan and I
(d) Define Data Aggregation with the help of an with 0.
example. (2)
(ii) Update s by dropping np.nan entries.

P.T.O.
5482-A 10 5482-A

(i) print(df.merge(df2, on=`Name')) (e) Differentiate between correlation and covariance.


(2)
(ii) print(df.merge(df2, on=`Name' , how=`left'))
(D Write the output of the following code snippet :
(iii) print(df.merge(df2, on=`Name', how=`right')) (2)

(iv) print(df.merge(df2, on= `Name', how=`outer')) df = pd.DataFrame( {`Product' :[`Apples' , `Oranges'],


`Price': [150, 200]))

(v) print(df.merge(df2, on=`Name', how=`inner'))


df[`Tax'] = df[`Price'] * 0.1

print(df)
6. (a) Given the following objects in python: (5)

(g) What is the use of np.arange() function? Give the


data = {`Group': [`A', `A', `8', `8', `C', `C'],
output of the following python statements: (3)
`Data': [10,15,10,15,10,15]}

(i) np.arange(5)
df = pd.DataFrame(data)

(ii) np.arange(10,1,-2)
Write the output for the following Python code :

(h) Write the output of the following code snippet:


(i) print(df.groupby(` Group' ).sum())
(3)
a = np.array([1, 2, 3, 4, 5])
(ii) print(df.groupby(` Group' ).mean())
b - a.copy()
(iii) print(df.groupby(`Group' ).count())
b[0] - 10

(iv) print(df.groupby(` Group ').max()) print(a)

print(b*2)
(v) print(df.groupby(` Group').min())
print(a+b)

P.T.O.
5482-A 5482-A

(i) Find the mean and median of the following (ii) Set the color of the line as green and style
data : (4) as a dotted line.

[12,13, 20, 9, 4,15,1]


(iii) Set the title of the plot as `Weekly Sales
vs Expenses'.
¢) Illustrate the concept of slicing and indexing in
Numpy arrays with examples. (4)
(iv) Set the label for the X-axis as `Week' and
Y-axis as `Amount..
(k) Differentiate between horizontal and vertical bar
plots. Write Python statements to plot a horizontal
(v) Save the resulting plot as `weekly-sales-
and vertical bar plot using the Matplotlib
expenses.jpg'.
lib rary. (4)

(b) Consider the python code given below : (10)


Sect:ion 8
data - (
`Name': [`Alice', `Bob', `Charlie', `David'],
2. (a) Write a Python code to create a lD array of
`Age': [25, 30, 35, 40],
numbers from 0 to 9 and perform the following
`Country': [`USA', `Canada', `USA', `Canada']
operations : (4)
)
(i) Reshape the array into a 2D array with 2 ` df = pd.DataFrame(data)
rows.
data2 - (
(ii) Multiply each element by 2. `ID' : [1, 2' 3, 4]'

`Name': [`Alice', `Bob', `Eve', `Charlie']


(b) Given the following dictionary data: (5)
)
data - ( df2 = pd.DataFrame(data2)
`Name': [`John', `Anna', `Peter', `Linda'],
`Age': [28, 34, 29, 32].
Write the output of the following Python
`City': [`New York', `Paris', `Berlin', `London.]
statements :
)

P.T.O.
5482-A 5482-A
Write the output for the following Python code: Write Python code for the following operations :

(i) print(df.dropna())
(i) Create a DataFrame from the dictionary
data and assign it to a variable named df.
(ii) print(df.fillna(method=`fflll'))

(ii) Add a new column `Salary' with values


(iii) print(df[`C'].mean())
[50000, 62000, 58000, 64000].
(iv) df[`D'] = dff`A'] + df[`B']
(iii) Filter the DataFrame `df' to show only the
print(df)
rows where `Age' is greater than 30.
(v) print(df.sum())
(iv) Calculate the average age of individual.

5. (a) Given a DataFrame df_sales representing weekly (v) Select and print the `Name' and `City'
sales data for a retail store : (5) columns for all individuals.

data = { `Week': [`Week 1', `Week 2', `Week 3',


`Week 4', `Week 5'], `Sales': [200,150, (c) Given the following Numpy array a : (6)

300, 250, 400], `Expenses': [150, 100,


a = np.array([[l, 2, 3],[4, 5, 6],[7, 8, 9]])
200,180, 300]

) What will be the shape of the following slicing


df_sales = pd.DataFrame(data) expressions?

Write Python code for the following operations :


(i) print(a[:2, :1] , a[: 2, : l].shape)

(i) Visualize the variation of both `Sales' and


(ii) print(a[2, :], a[2, :].shape)
`Expenses' over a 5-week period using a

line graph. (iii) print(a[l: 2, : 2] , a[l:2, : 2].shape)

P.T.0.
5482-A 5482-A

3. (a) Given the following Numpy array data : (5) 4. (a)Given a series data: (5)

data = pd.Series([l, 3, 5, 7, 9], index=[`one', `two',


data = np.array([[l,2], [4,5], [7,8]])
`three', `four', `five'])

Write the output for the following Python code :


Write the output for the following Python code :

(i) print(data[1,1])
(i) print(data[:])

(ii) print(data.sum(axis = 1)) (ii) print(data[`two' : `four'])

(iii) print(data.T) (iii) print(data.index)

(iv) print(data.reindex([`two', `one', `five',


(iv) print(data > 5) `four', `three', `six']))

(v) print(data[data > 5])


(v) print(data.drop(`one'))

(b) Given a DataFrame df : (5)


(b) Explain the difference between descriptive
statistics and inferential statistics. Provide an
df = pd.DataFrame({`Height': [5.5, 6.I, 5.9, 5.7,
example scenario for each. (5)
6.2], `Weight': [60, 70, 80, 65, 90]})

(c) Given a DataFrame df : (5)


Write Python code to calculate the Body Mass
Index (`BMI') for each individual and add it as df = pd.DataFrame({
a new column. BMI is calculated as Weight/ `A': [1, 2, np.nan, 4],

(Height)2.
`8': [5, np.nan, np.nan, 8],

`C': [10, 20, 30, 40]


(c) Describe the use of the pivot_table() function in
Pandas with the help of an example. (5)
))

P.T.O.

You might also like