Q. Write the python statement for the following question on the basis of given datasets:
a) To create the above DataFrame.
b) To print the Degree and maximum marks in each stream.
c) To fill the NaN with 76.
d) To set the index to Name.
e) To display the name and degree wise average marks of each student.
f) To count the number of students in MBA.
g) To print the mode marks BCA.
Answer :-
(a)
d=['mba','bca','mtech'] dic={'Name':['aparna','pankaj','ram','ramesh'],'Degree':d+['mba'],'score':[90,np.NaN,80,98]} df1=pd.DataFrame(dic) print(df1)
(b)
print(df[‘Degree’]) #code for maximum marks in each stream. import numpy as np import pandas as pd d=['mba','bca','mtech'] dic={'Name':['aparna','pankaj','ram','ramesh'],'Degree':d+['mba'],'score':[90,np.NaN,80,98]} df1=pd.DataFrame(dic) print(df1) print() for y in d: print(f'max score in {y} is ') print(df1[df1['Degree']==y].max()) print() print()
(c)
df1.fillna(76)
(d)
(e)
print('degree wise average marks of each student. ') for y in d: print(f' average score in {y} is ') print(df1[df1['Degree']==y].mean()) print() print()
(f)
len(df1[df1['Degree']=='mba'])
(g)
df1[df1['Degree']=='bca'].mode()
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )