Class 11 – Informatics Practices
Question Paper – Python Pandas Part I
Topic: Pandas – Series and DataFrame
Time: 2 Hours
Max Marks: 40
General Instructions:
- All questions are compulsory.
- Answer the questions as directed.
- Write code clearly with correct syntax and indentation.
Section A: Multiple Choice Questions (1 × 6 = 6 Marks)
1. Which of the following is the correct way to import pandas?
a) import panda
b) from pandas import *
c) import pandas as pd
d) include pandas
2. A Series in pandas is a:
a) 2D labeled array
b) 1D labeled array
c) List
d) Dictionary
3. Which method is used to display the first 5 rows of a DataFrame?
a) df.start()
b) df.tail()
c) df.show()
d) df.head()
4. What will s[1] return if s = pd.Series([10, 20, 30])?
a) 10
b) 20
c) 30
d) Error
5. What is the default index of a pandas Series?
a) A-Z
b) 0, 1, 2...
c) Row names
d) None of the above
6. Which function is used to check the number of rows and columns in a DataFrame?
a) df.size()
b) df.count()
c) df.shape
d) df.total()
Section B: Fill in the Blanks (1 × 5 = 5 Marks)
7. Pandas is built on top of the __________ library.
8. A __________ is a 2-dimensional labeled data structure in pandas.
9. pd.Series() by default uses __________ index values.
10. df.columns returns a list of __________ of the DataFrame.
11. The method __________ is used to read a CSV file into a DataFrame.
Section C: True or False (1 × 5 = 5 Marks)
12. A pandas Series can store mixed data types. (______)
13. A DataFrame can only be created from lists. (______)
14. The head() function is used to add rows to a DataFrame. (______)
15. The axis parameter in drop() function is used to specify whether to drop rows or
columns. (______)
16. DataFrames can have custom indexes. (______)
Section D: Short Answer Questions (2 × 6 = 12 Marks)
17. Write Python code to create a Series marks = [80, 90, 85] with index ['Math', 'English',
'Science'].
18. List any four differences between Series and DataFrame.
19. Write code to create a DataFrame from a dictionary containing the following data:
{'Name': ['Ali', 'Sara'], 'Age': [16, 17], 'Class': ['XI', 'XI']}
20. What is the purpose of index and columns in a DataFrame?
21. Explain the use of the dtype attribute in Series or DataFrame.
22. What is the output of the following code:
import pandas as pd
s = pd.Series([5, 10, 15], index=['a', 'b', 'c'])
print(s['b'])
Section E: Long Answer Questions (3 × 2 = 6 Marks)
23. Write a Python program to:
- Create a DataFrame from a dictionary
- Display the first 2 rows using head()
- Display column names using columns
24. Explain three different ways to create a Series in pandas with examples.
Section F: Code Analysis/Correction (1 × 1 = 1 Mark)
25. Find and correct the error in the following code:
import pandas as pd
data = [10, 20, 30]
s = pd.Series(data, index=('a', 'b', 'c'))
print(s)