Class 12 IP Practical File Question & Answer 2021
Class 12 IP Practical File Question & Answer 2021
th
Class 12 IP Practical File With Solution
Python Program
Q.1 Write a Python Program to create the Series data structure using list items and display its.
import pandas as pd
y=pd.Series([15,18,17,15,20,12],["a","b","c","d","e","f"],dtype="int32")
print(y)
Output
a 15
b 18
c 17
d 15
e 20
f 12
dtype:int32
Q.2 Write a Python Program to create the Series data structure using Dictionary and display all its
attributes.
import pandas as pd
y=pd.Series({"Rollno":1,"Name":"Amit","Class":11,"City":"Jaipur","DOB":None})
print("Your Series Data Structure As Follows:\n",y,"\n")
print("Your index As Follows:",y.index)
print("Your Data As Follows:",y.values)
print("Data Type of Series:",y.dtype)
print("Shape of Series is:",y.shape)
print("Number of Dimension:",y.ndim)
print("Size of Series:",y.size)
print("Number of Bytes:",y.nbytes)
print("Have None Data:",y.hasnans)
print("Empty Series:",y.empty)
Output
import pandas as pd
b=pd.DataFrame([[1,"Mohan",12],[2,"Kapil",11],[3,"Amita",11],[4,"Madhu",11],[5,"Priya",12]],columns=
["rollno", "name","age"],index=["S1","S2","S3","S4","S5"])
print(b)
Output
rollno name age
S1 1 Mohan 12
S2 2 Kapil 11
S3 3 Amita 11
S4 4 Madhu 11
S5 5 Priya 12
Q.4 Write a Python Program to create the Series data structure using Dictionary and display all its
attributes.
import pandas as pd
y=pd.DataFrame({"Physics":[20,10,12,12],"Chemistry":[14,15,14,14],"Biology":[12,15,16,18],"English":[18,20,2
0,19]},index=["C1","c2","c3","C4"])
print("Your Data Frame As Follows:\n",y,"\n")
print("Your index As Follows:",y.index,"\n")
print("Your Columns As Follows:",y.columns,"\n")
print("Details of Both Axis are As Follows:",y.axes,"\n")
print("Your Data As Follows:",y.values,"\n")
print("Data Type of Series:",y.dtypes,"\n")
print("Shape of Series is:",y.shape,"\n")
Output
Your Data Frame As Follows:
Physics Chemistry Biology English
C1 20 14 12 18
c2 10 15 15 20
c3 12 14 16 20
C4 12 14 18 19
Details of Both Axis are As Follows: [Index(['C1', 'c2', 'c3', 'C4'], dtype='object'), Index(['Physics', 'Chemistry',
'Bi ology', 'English'], dtype='object')]
import pandas as pd
L=pd.DataFrame({"Rollno":[101,102,103,104],"Name":["Abhay","Somya","Priya","Divya"],"Physics":[20,10,12,1
2],"Chemistry":[14,15,14,14],"Biology":[12,15,16,18],"English":[18,20,20,19]},index=["S1","S2","S3","S4"])
print(L)
x=1
while (x != 0):
print("1. To Display a Column from Data Frame")
print("2. To Display a Row From Data Frame")
print("3. To Display DataFrame")
print("4. To Display the Top Rows Of Data Fram")
print("5. To Display the Bottom Rows Of Series")
print("6. To Display the Specific Data from Data Frame")
print("7. To Add / Update a Row in Data Frame")
print("8. To Add a Column in Data Frame")
print("9. To Update a Specific Data in Data Frame")
print("10.To Delete a Row from Data Frame")
print("11.To Delete a Column from Data Frame")
print("0. For Exit")
x = int(input("Enter choice = "))
if (x == 1):
ind = input("Enter Column Name")
print(L[ind])
elif (x == 2):
ind = input("Enter Row Index No")
print(L.loc[ind])
elif (x == 3):
print(L)
elif (x == 4):
val = int(input("Number of Rows want to display from Top "))
print(L.head(val))
elif (x == 5):
val = int(input("Number of Rows want to display from Bottom "))
print(L.tail(val))
elif (x == 6):
ival = input("Enter the Index Number want to display")
cval = input("Enter the Column Name want to display")
print(L.loc[ival,cval])
elif (x == 7):
ival = input("Enter the Index Number want to Add / Modify")
rn = int(input("Enter the Roll No:"))
nm = input("Enter the Name:")
phy = int(input("Enter Physics Marks"))
chem = int(input("Enter Chemistry Marks:"))
bio = int(input("Enter Biology Marks:"))
eng = int(input("Enter English Marks:"))
L.loc[ival]=[rn,nm,phy,chem,bio,eng]
elif (x == 8):
cval = input("Enter the Column Name want to Add")
L[cval]=None
elif (x == 9):
ival = input("Enter the Index Number")
cval = input("Enter the Column Name")
val = input("Enter the Data:")
L.loc[ival,cval]=val
elif (x == 10):
val = input("Enter the Index Number Want to Delete")
L=L.drop(val)
elif (x == 11):
val = input("Enter the Column Name Want to Delete")
del L[val]
print("\n--------------------------------------------------------------------\n\n\n")
Q.6 Write a Python Program to change column and index, sorting of data in data frame.
import pandas as pd
L=pd.DataFrame({"Rollno":[101,102,103,104],"Name":["Abhay","Somya","Priya","Divya"],"Physics":[20,10,12,1
2],"Chemistry":[14,15,14,14],"Biology":[12,15,16,18],"English":[18,20,20,19]},index=["S1","S2","S3","S4"])
print(L)
x=1
while (x != 0):
print("1. To Display Data Frame")
print("2. To Change Column Name")
print("3. To Change Index Number")
print("4. To Sort the Data by Column Name")
print("5. To Sort the Data by Index Number")
print("0. For Exit")
x = int(input("Enter choice = "))
if (x == 1):
print(L)
elif (x == 2):
ocol = input("Enter Column Name want to change")
ncol = input("Enter New Column Name")
L=L.rename(columns={ocol:ncol})
elif (x == 3):
oind = input("Enter Index Number want to change")
nind = input("Enter New Index Number")
L=L.rename(index={oind:nind})
elif (x == 4):
col = input("Enter Column Name")
L=L.sort_values(col)
print(L)
elif (x == 5):
L=L.sort_index()
print(L)
print("\n--------------------------------------------------------------------\n\n\n")
Q.7 Write a Python Program to implement all operations on a DataFrame.
import pandas as pd
L=pd.DataFrame({"Rollno":[101,102,103,104],"Name":["Abhay","Somya","Priya","Divya"],"Physics":[20,10,12,1
2],"Chemistry":[14,15,14,14],"Biology":[12,15,16,18],"English":[18,20,20,19]},index=["S1","S2","S3","S4"])
print(L)
x=1
while (x != 0):
print("1. To Display Data Frame")
print("2. To Count the total number of Item in Each Column")
print("3. To Find the sum of Each Column")
print("4. To Find the Minimum Value in Each Column")
print("5. To Find the Maximum Value in Each Column")
print("6. To Count the total number of Item in Each Row")
print("7. To Find the sum of Each Row")
print("8. To Find the Minimum Value in Each Row")
print("8. To Find the Maximum Value in Each Row")
print("0. For Exit")
x = int(input("Enter choice = "))
if (x == 1):
print(L)
elif (x == 2):
ans=L.count(axis=0)
print(ans)
elif (x == 3):
ans=L.sum(axis=0,numeric_only=True)
print(ans)
elif (x == 4):
ans=L.min(axis=0,numeric_only=True)
print(ans)
elif (x == 5):
ans=L.max(axis=0,numeric_only=True)
print(ans)
elif (x == 6):
ans=L.count(axis=1)
print(ans)
elif (x == 7):
ans=L.sum(axis=1,numeric_only=True)
print(ans)
elif (x == 8):
ans=L.min(axis=1,numeric_only=True)
print(ans)
elif (x == 9):
ans=L.max(axis=1,numeric_only=True)
print(ans)
print("\n--------------------------------------------------------------------\n\n\n")
Q.8 Write a Python program to create a data frame then export it in CSV file then import from there amd
display the data from it.
import pandas as pd
L=pd.DataFrame({"Rollno":[101,102,103,104],"Name":["Abhay","Somya","Priya","Divya"],"Physics":[20,10,12,1
2],"Chemistry":[14,15,14,14],"Biology":[12,15,16,18],"English":[18,20,20,19]},index=["S1","S2","S3","S4
"])
L.to_csv("d://py/mydata.csv")
data=pd.read_csv("d://py/mydata.csv",index_col=0)
print(data)
Output
Rollno Name Physics Chemistry Biology English
S1 101 Abhay 20 14 12 18
S2 102 Somya 10 15 15 20
S3 103 Priya 12 14 16 20
S4 104 Divya 12 14 18 19
Q.9 Write a Python Program to create a line graph for fare from Jaipur to different cities.
import matplotlib.pyplot as py
py.figure(figsize=(10,10))
a=["Ajmer","Kota","Alwar","Bikaner"]
b=[200,500,350,450]
py.plot(a,b,linewidth=5)
Output
Q.10 Write a Python Program to create a multiple line graph for marks in each subject for class.
import pandas as pd
import matplotlib.pyplot as py
L=pd.DataFrame({"Rollno":[101,102,103,104],"Name":["Abhay","Somya","Priya","Divya"],"Physics":[20,10,12,1
2],"Chemistry":[14,15,14,14],"Biology":[12,15,16,18],"English":[18,20,20,19]},index=["S1","S2","S3","S4"])
print(L)
Output
Q.11 Write a Python Program to create a bar graph for no of student in school in every year.
import matplotlib.pyplot as py
a=[2016,2017,2018,2019,2020]
b=[1200,1500,1350,1450,1800]
py.bar(a,b,color="RED")
py.title("Yearwise Student in School")
py.xlabel("Year")
py.ylabel("Number of Student")
py.show()
Output
Q.12 Write a Python Program to create a horizontal bar graph for number of student in school in each class
import matplotlib.pyplot as py
py.barh(['I','II','III','IV','V','VI','VII','VIII'],[130,135,142,137,139,146,175,200])
Output
Q.13 Write a Python Program to create a histogram for age of the 20 student in class.
import matplotlib.pyplot as py
py.hist([10,12,15,12,11,12,15,12,12,11,10,10,11,12,11,12,11,10,13,14])
py.title("Age Chart")
py.xlabel("Age")
py.ylabel("Number of Student")
py.show()
Output