Q. Consider the original Data Frame mk. Write a program to calculate average marks for each section.
DataFrame mk :-
A B C D
Acct 99 94.0 92 97.0
Eco 90 94.0 92 97.0
Eng 95 89.0 91 89.0
IP 94 NaN 99 95.0
Math 97 100.0 99 NaN
Answer :-
import pandas as pd import numpy as np x = { 'A': {'Acct': 99, 'Eco' : 90, 'Eng': 95,\ 'IP' : 94, 'Math': 97},\ 'B' : { 'Acct': 94, 'Eco':94, 'Eng': 89,\ 'IP' : np.NaN, 'Math' : 100},\ 'C': {'Acct': 92, 'Eco' : 92, 'Eng' : 91,\ 'IP' :99, 'Math':99},\ 'D': {'Acct':97, 'Eco': 97, 'Eng': 89,\ 'IP' : 95, 'Math': np.NaN}} df = pd.DataFrame (x) print("Average marks section wise") print(df.mean())
Output :-
Average marks section wise
A 95.00
B 94.25
C 94.60
D 94.50
dtype: float64
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )