St.
Stephen's Public School, Kudassanad
PT-2 Examination 2025
Class XII – Informatics Practices (065)
Time: 1½ Hours Max Marks: 40
Section A: Multiple Choice Questions (1×6 = 6 Marks)
I. Choose the correct option:
1. Which function is used to read a CSV file into a DataFrame?
a) read_csv() b) open_csv() c) import_csv() d) load_csv()
2. What is the result of df.shape if df has 4 rows and 3 columns?
a) (3, 4) b) (4, 3) c) [4, 3] d) 4x3
3. Which method returns the number of non-null values in each column?
a) count() b) value_counts() c) notnull() d) shape
4. Which method is used to remove rows with missing values?
a) fillna() b) dropna() c) removena() d) skipna()
5. Which command selects the first 5 rows of DataFrame df?
a) df.tail(5) b) df.first(5) c) df.head(5) d) df.top(5)
6. What does df['Marks'] > 50 return?
a) Filtered DataFrame b) Boolean Series c) Error d) Column
Section B: Assertion and Reasoning (1×2 = 2 Marks)
II. Choose the correct option (A/B/C/D):
7. Assertion (A): The loc[] method allows label-based indexing.
Reason (R): loc[] can only be used for numeric indices.
(A) Both A and R are true, and R is the correct explanation of A.
(B) Both A and R are true, but R is not the correct explanation of A.
(C) A is true but R is false.
(D) A is false but R is true.
8. Assertion (A): dropna() removes rows with missing values.
Reason (R): dropna() fills missing values with zero.
(A) Both A and R are true, and R is the correct explanation of A.
(B) Both A and R are true, but R is not the correct explanation of A.
(C) A is true but R is false.
(D) A is false but R is true.
Section C: Short Answer Questions (2×6 = 12 Marks)
9. Write the output of the following:
import pandas as pd
s = pd.Series([10, 20, 30], index=['a', 'b', 'c'])
print(s['b'])
print(s.iloc(2:))
10. Given the DataFrame:
Name Marks
A 90
B 70
C 80
a) Write a command to display names of students with marks > 75.
b) Write a command to add a new column Grade with value 'A' in all rows of DataFrame
12. Write a Pandas command to create a DataFrame from the dictionary:
{'ID': [101, 102], 'Name': ['Ravi', 'Asha']}
13. What is the output of:
df = pd.DataFrame({'A':[1, 2], 'B':[3, 4]})
print(df.shape)
print(df.index)
14. What is the output of:
df = pd.DataFrame({'x':[5, 10, 15]})
print(df.iloc[1])
15. Differentiate between Series and Dataframe?
Section D: Long Answer Questions (4×5 = 20 Marks )
16. Create a DataFrame from the following data and write commands to:
{'RollNo': [1, 2, 3], 'Name': ['Anil', 'Sunita', 'Ravi'], 'Marks': [85, 90, 75]}
a) Display all columns
b) Display only the 'Name' column
c) Add a column 'Grade' with all values as 'B'
17. Given a DataFrame:
Name Age
Amit 22
Rani 19
Write statements to:
a) Add a new row ['Vijay', 21]
b) Delete the row with index 1
c) Rename column 'Age' to 'Years'
18. Consider the DataFrame df shown below.
Name Price Rating
0 Note Book 100 5
1 Project File 120 7
2 Pen Drive 325 6
3 IP Book 500 3
Write Python statements for the DataFrame df to:
i. Print the first two rows of the DataFrame df.
ii. Display titles of all the books.
iii. Remove the column rating.
iv. Display the data of the 'Name' column from indexes 1 to 3 (both included).
OR
v. Rename the column name 'Name' to 'Title'.
19. a) Write a Python Program to create a Pandas Series as shown below using a dictionary.
Note that the left column indicates the indices
b) Sumita is writing a Python program to create a DataFrame using a list of dictionaries.
However, her code contains some mistakes. Identify the errors, rewrite the correct code,
and underline the corrections made.
Import pandas as pd
D1 = ['Name': 'Sumit', 'Age': 35]
D2 = {'Name': 'Parul', 'Age': 20}
D3 = {'Name': 'Ameesha', 'Age”: 38}
data = [D1,D2,D3]
df = pd.Dataframe(data)
print(df)
20. A CSV file named students.csv contains the following data:
RollNo,Name,Marks
101,Anya,85
102,Ravi,91
103,Simran,78
104,Aarav,88