PYTHON PANDAS COMPREHENSIVE PRACTICE

CBSE Informatics Practices (065) | 2025-26 Session

Question 1: Consider the following DataFrame Doctor and write Python statements:

IndexDIDNameDepartmentFee
0101Dr. JoeENT1500
1102Dr. SalmaUROLOGY1600
2103Dr. JeetORTHO1550
3104Dr. NehaENT1200
4105Dr. VikramORTHO1700
[+] I. Print last 3 rows of the DataFrame
print(Doctor.tail(3))
[+] II. Display the names of all doctors
print(Doctor['Name'])
# OR
print(Doctor.Name)
[+] III. Add column 'Discount' with value 200 for all
Doctor['Discount'] = 200
[+] IV. Display rows with index 2 and 3
print(Doctor.loc[2:3])
[+] V. Delete the column 'Department'
del Doctor['Department']
# OR
Doctor = Doctor.drop('Department', axis=1)

DataFrame Creation

Question 2: Create the following DataFrame using a Dictionary of Series:

CityState
0MumbaiMaharashtra
1DehradunUttarakhand
2BengaluruKarnataka
[+] Click to see the Python Code
import pandas as pd

c = pd.Series(['Mumbai', 'Dehradun', 'Bengaluru'])
s = pd.Series(['Maharashtra', 'Uttarakhand', 'Karnataka'])

data = {'City': c, 'State': s}
df = pd.DataFrame(data)
print(df)

Fill in the Blanks

Question 3: Complete the code to get the output (Colour, Name, Qty):

import ______ (1) as pd
data = [{'COLOUR':'Red', 'NAME':'Apple', 'QTY':10},
{'______ (2)':'Blue', 'NAME':'Berry', 'QTY':15},
{'COLOUR':'Green', 'NAME' :'Guava','QTY':20}]
df = pd.DataFrame(______ (3))
print(______ (4))
[+] Reveal Answers
1. pandas
2. COLOUR
3. data
4. df