Programs Using Pandas

Q Write a program to create dataframe for 3 student including name and roll numbers. and add new columns for 5 subjects and 1 column to calculate percentage. It should include random numbers in marks of all subjects

import pandas as pd, numpy as np, random
D={‘Roll’:[1,2,3],’Name’:[‘Sangeeta’,’Shanti’,’Swati’]}
P=[]
C=[]
M=[]
E=[]
H=[]
SD=pd.DataFrame(D)
for i in range(3):
P.append(random.randint(1,101))
C.append(random.randint(1,101))
M.append(random.randint(1,101))
E.append(random.randint(1,101))
H.append(random.randint(1,101))
SD[‘Phy’]=P
SD[‘Chem’]=C
SD[‘Maths’]=M
SD[‘Eng’]=E
SD[‘Hin’]=H

SD[‘Total’]=SD.Phy+SD.Chem+SD.Maths+SD.Eng+SD.Hin
SD[‘Per’]=SD.Total/5

print(SD)