CBSERanker

Loading

PRACTICE TEST APRIL IP CLASS 12

PRACTICE TEST APRIL IP CLASS 12

Section A: Multiple Choice Questions (1 mark each)

Q1. What does the acronym “Pandas” stand for in data analysis?
A) Python Data Analysis
B) Panel Data System
C) Python Data System
D) Panel Data

Q2. Which command is used to install the Pandas library?
A) install pandas
B) pip install pandas
C) python install pandas
D) pip pandas

Q3. Which of the following is true about Pandas Series?
A) It can only be created from lists.
B) It cannot have duplicate indexes.
C) It can be created from dictionaries, where keys become indexes.
D) It is immutable.

Q4. What will be the output of the following code?

import pandas as pd 

s = pd.Series(data=2*[5, 6]) 

print(s) 

A) [5, 6, 5, 6]
B) [5, 6] repeated twice
C) [5, 6, 10, 12]
D) Error

Q5. How many values will be in the Series if the following code runs without error?

s = pd.Series(lst, index=list(‘ABCDE’)) 

A) 4
B) 5
C) Depends on lst
D) Error

Q6. What will be the output of the following code?

S1 = pd.Series([10, 20, 30], index=range(2, 8, 3)) 

print(S1) 

A) 2:10, 5:20, 8:30
B) 2:10, 5:20
C) 10, 20, 30
D) Error

Q7. Fill in the blank to get the output as 30:

s = pd.Series([10, 20, 30, 40], index=list(‘wxyz’)) 

print(s[_____]) 

A) ‘y’
B) 2
C) ‘z’
D) All of the above

Q8. Which statement will print a Series s in reverse order?
A) print(s[::-1])
B) print(s.reverse())
C) print(s[-1::])
D) print(s[::1])

Q9. Which attribute returns the total number of values in a Series S?
A) size
B) count
C) index
D) values

Q10. The statement S1[3:5] = 100 will update the value of how many elements?
A) 1
B) 2
C) 3
D) 4

Q11. What will be the output of the following code?

S1 = pd.Series() 

print(S1.empty) 

A) True
B) False
C) Error
D) None

Q12-Q14. For the following code, answer the questions:

L = [5, 10, 15, 20] 

S1 = pd.Series(L) 

S2 = pd.Series(L[1:]) 

S3 = S1 + S2 

Q12. What will print(S3) output?
A) [5, 10, 15, 20]
B) [NaN, 20, 30, 40]
C) [5, 20, 30, 40]
D) Error

Q13. What will print(S3.head(2)) output?
A) First 2 values of S3
B) Last 2 values of S3
C) First 2 indexes of S3
D) Error

Q14. What will print(S3.tail(1)) output?
A) Last value of S3
B) First value of S3
C) All values of S3
D) Error

Q15. Which statement will display values greater than 50 from Series S1?
A) S1 > 50
B) S1[S1 > 50]
C) S1.where(S1 > 50)
D) S1.filter(S1 > 50)

Q16. Can a Pandas Series have duplicate indexes? (True/False)

Q17. Will the following two statements give the same output? (True/False)

L1 * 2  # L1 is a list 

S1 * 2  # S1 is a Series 

Q18. A Pandas Series is size _____ and values _____.
A) Mutable, Mutable
B) Immutable, Immutable
C) Mutable, Immutable
D) Immutable, Mutable

Q19. Which attribute checks for NaN values in a Series?
A) has_nans
B) isna()
C) hasna()
D) isnull()

Q20. Which function sorts a Series by its values?
A) sort_values()
B) sort()
C) order()
D) arrange()

Section B: Short Answer Questions (2 marks each)

Q21. Write a Python program to create a Pandas Series from the list [15, 25, 35, 45].

Q22. Create a Series from the dictionary {‘x’: 100, ‘y’: 200, ‘z’: 300} and display it.

Q23. What will be the output of the following code?

import pandas as pd 

s = pd.Series([8, 12, 16, 20], index=[‘p’, ‘q’, ‘r’, ‘s’]) 

print(s[‘r’]) 

Section C: Descriptive Questions (3 marks each)

Q24. Create a Pandas Series named temperatures with the following data:
[32, 35, 28, 30, 34]
Assign the index later as [‘Mon’, ‘Tue’, ‘Wed’, ‘Thu’, ‘Fri’] and print the Series.

Q25. Given the Series:

data = pd.Series([100, 200, 300, 400, 500], index=[‘a’, ‘b’, ‘c’, ‘d’, ‘e’]) 

Write the code to:
a) Access the value at index ‘d’.
b) Display the last 3 elements using slicing.
c) Check if ‘f’ is present in the index.

Section D: Long Answer Questions (4 marks each)

Q26. Create two Series:

s1 = pd.Series([5, 10, 15, 20], index=[‘a’, ‘b’, ‘c’, ‘d’]) 

s2 = pd.Series([2, 4, 6, 8], index=[‘a’, ‘b’, ‘d’, ‘e’]) 

Perform the following operations:
a) Add s1 and s2.
b) Multiply s1 and s2.
Explain what happens when indexes do not match.

Q27. Given the Series:

s = pd.Series([50, 60, 70, 80, 90], index=[‘A’, ‘B’, ‘C’, ‘D’, ‘E’]) 

Write the code to:
a) Display the index and values separately.
b) Find the maximum and minimum values.
c) Calculate the mean of the Series.
d) Convert the Series to a dictionary.

Leave a Reply

Your email address will not be published. Required fields are marked *