CLASS XII | INFORMATICS PRACTICES
DATA FRAMES REVISION ASSIGNMENT
Q1. Create the following dataframes:
i. CricketPlayers from a list of dictionaries containing names of five cricket players,
number of matches played and Average Score.
ii. Items from a list of dictionaries containing names of five items, cost price, sales
price, discount(if any).
iii. Result from a dictionary of series containing rollnumber of 6 students and their
percentage in last five years
iv. Monuments from a dictionary of series containing names of 10 monuments, their
year of built, place and who built them
v. Countries from a list of dictionaries containing names of 10 countries, its national
animal, bird and currency.
Q2. Consider the following dataframe RESULTSHEET:
UT1 Half Yearly UT2 Final
Sharad 57 83 49 89
Mansi 86 67 87 90
Kanika 92 78 45 66
Ramesh 52 84 55 78
Ankita 93 75 87 69
Pranay 98 79 88 96
Here, Names of the students are row labels and term names (UT1, Half Yearly, UT2 and
Final) are the column labels. Answer the following questions based on the above dataframe:
a. Change the row labels from student name to roll numbers from 1 to 6.
b. Change the column labels to Term1, Term2, Term3, Term4.
c. Add a new column Internal Assessment with values ‘A’, ‘A’,’B’,’A’,’C’, ‘B’
d. Add a new row for the student with name = Asatha and marks equal to 49, 56, 75,58.
e. Delete the first row
f. Delete the third column
g. Rename Mansi to Mahak
h. Display 2nd row with all columns
i. Display how many students have scored more than 50 in Final exam
j. Check how many students have grade as A
k. Display marks in Half Yearly and Final of all students
l. Display all marks of students from Mansi to Ankita
m. Display marks of Mansi to Ankita in UT1 and UT2
n. Display marks of Kanika and Ankita in Half Yearly and Final
o. Display first 3 records
p. Display last four records
Q3. Write a Python program to create the following dataframe DOCTOR using the index
values as 10,20,30,40, 50, 60, 70.
ID NAME DEPT EXPERIENCE
101 JOHN ENT 12
102 SMITH ORTHOPEDIC 5
103 GEORGE CARDIOLOGY 10
104 LARA SKIN 3
105 K GEORGE MEDICINE 9
106 JOHNSON ORTHOPEDIC 10
107 LUCY ENT 3
Q4. Give commands to perform the following operations on the dataframe DOCTOR:
i. Write code to display the details of LARA using loc.
ii. Write code to display the details of LARA and LUCY using iloc.
iii. Write code to display all doctor’s names.
iv. Write code to display all doctor’s names along with DEPT
v. Write code to display the first 3 records from the dataframe.
vi. Write code to display the last 4 records from the data frame.
vii. Write code to display the department and experience of doctors with names JOHN
and SMITH.
viii. Write code to display 2nd to 6th record
ix. Display all the odd numbered records.
x. Display all the even numbered records.
xi. Write code to insert a column named “AGE” giving appropriate values to each
doctor.
xii. Write code to delete column AGE
xiii. Write code to rename all row labels to 100,200,300,400,500,600,700,800,900
xiv. Write code to rename column labels to Doc_id, Doc_name, Department and Exp.
xv. Write code to display alternate records from the bottom.
Q5. Give the output:
a. import pandas as pd
l1=[{1:"Ramit",2:"Sahil",3:"Mohit"}, {1:"Akshay",3:"Sanjana"}]
df=pd.DataFrame(l1)
print(df)
b. import pandas as pd
a=[[10,"Ankit"],[20,"Chanchal"],[30,"Ramesh"],[40,"Vikul"]]
b=pd.DataFrame(a)
print(b)
c. import pandas as pd
d1={"Itemno":[1,2,3], "Selling_Price":[350.5,400,420], "Cost_Price":[270,180,284]}
df1=pd.DataFrame(d1)
print(df1)
d. import pandas as pd
d2={"Empno":pd.Series([“A101”,”B102”,”C103”,”D104”]),
"Salary":pd.Series([350.5,400,420]), "Bonus":pd.Series([70,80,84,80])}
df2=pd.DataFrame(d2)
print(df2)
e. import pandas as pd
a=[[10,"Ankit"],[20,"Chanchal"],[30,"Ramesh"],[40,"Vikul"]]
b=pd.DataFrame(a, index=[1,2,3,4], columns=["Roll No.", "Name"])
print(b)
f. import pandas as pd
d2={"Empno":pd.Series([“A101”,”B102”,”C103”,”D104”], index=[1,2,3,4]),
"Salary":pd.Series([350.5,400,420], index=[1,2,4]), "Bonus":pd.Series([70, 84,80],
index=[1,3,4])}
df2=pd.DataFrame(d2)
print(df2)
Q6. Consider the following DataFrame Flight_Fare:
FL_NO AIRLINES FARE
IC701 INDIAN AIRLINES 6500
MU499 SAHARA 9400
AM501 JET AIRWAYS 13400
IC899 INDIAN AIRLINES 8300
IC302 INDIAN AIRLINES 4300
Give the output of the following commands:
a. >>> Flight_Fare ["Tax%"] = [10,8,9,5,7]
>>> Flight_Fare
b. >>> Flight_Fare.loc[5]=[ "MC101", "DECCAN AIRLINES", "3500"]
>>> Flight_Fare
c. >>> loc [:,"Disc%"] = [2,3,2,4,2]
>>> Flight_Fare
d. drop("Tax%", axis=1)
e. Flight_Fare.drop(4, axis=0)
f. Flight_Fare.drop([1,4] , axis=0)
g. Flight_Fare.drop(["FARE", "Tax%"] , axis=1)
h. Flight_Fare.loc[2]
i. Flight_Fare.loc[:,"FL_NO"]
j. Flight_Fare ["FARE"]>=6000
k. Flight_Fare [Flight_Fare.index>1]
l. Flight_Fare [( Flight_Fare .FARE>=4000)&( Flight_Fare .FARE<=9000)]
m. Flight_Fare [( Flight_Fare .FL_NO== "IC701")| ( Flight_Fare .FL_NO== "AM501")|
( Flight_Fare .FL_NO== " IC302")]
n. Flight_Fare [( Flight_Fare .FARE>=4000)&( Flight_Fare .FARE<=9000)][[ "FL_NO",
"FARE"]]
o. Flight_Fare [2:4]
p. Flight_Fare [:4]
q. Flight_Fare [::3]
r. Flight_Fare [:: -3]
s. Flight_Fare [3:]
t. Flight_Fare.loc[1:4,'FL_NO':'FARE']
u. Flight_Fare.loc[1:4,['FL_NO','FARE']]
v. Flight_Fare.iloc[[0,2,4]]
w. Flight_Fare.iloc[:,1:3]
x. Flight_Fare.iloc[1:2,1:3]
y. Flight_Fare.loc[1:3]
z. Flight_Fare.loc[:,'FL_NO':'FARE']
Question 7 and 8 are not part of the syllabus for the batch 2020-21
Q7. Consider a dataframe STUDETAILS with the following information:
Class Section
Sharad 12 A
Mansi 12 A
Radhika 12 A
Ramesh 11 B
Mohit 11 B
Pranay 11 B
i. Write a command to join dataframes: STUDETAILS and RESULTSHEET.
ii. Write a command to display records which are present in both the dataframes.
iii. Write a command to join two dataframes display data corresponding to only those
records which are present in the dataframe RESULTSHEET.
iv. Write a command to join two dataframes display data corresponding to only those
records which are present in the dataframe STUDDETAILS.
Q8. Consider the following two dataframes:
SHEET1
Name Half Yearly Final
Sharad 83 89
Mansi 67 90
Kanika 78 66
Ramesh 84 78
SHEET2
Name Half Yearly Final
Ankita 75 69
Pranay 79 96
Abhay 87 98
i. Write Python command to join the above two dataframes row wise.
ii. Write Python command to join the above two dataframes column wise.