Thursday, 11 March 2021

Class 12 IP Practical - 25

 

25. WAP to calculate median and mean for each subject in DataFrame dfmks.

 

A

B

C

D

Acct

99

97

92

97

Eco

94

94

92

97

Eng

95

89

91

89

IP

94

87

99

94

Math

97

87

99

99

 

 

import pandas as pd

import numpy as np

d={'A':{'Acct':99,'Eco':94,'Eng':95,'IP':94,'Math':97}, \

   'B':{'Acct':97,'Eco':94,'Eng':89,'IP':87,'Math':87}, \

   'C':{'Acct':92,'Eco':92,'Eng':91,'IP':99,'Math':99}, \

   'D':{'Acct':97,'Eco':97,'Eng':89,'IP':94,'Math':99}}

 

dfmks=pd.DataFrame(d)

print("DataFrame is: ")

print(dfmks)

print("Mean Value for each subject: ")

print(dfmks.mean(axis=1))

print("Median Value for each Subject: ")

print(dfmks.median(axis=1))

 

>>>

======================= RESTART: C:/Program Files (x86)/Python38-32/IP-25.py ======================

DataFrame is:

       A   B   C   D

Acct  99  97  92  97

Eco   94  94  92  97

Eng   95  89  91  89

IP    94  87  99  94

Math  97  87  99  99

Mean Value for each subject:

Acct    96.25

Eco     94.25

Eng     91.00

IP      93.50

Math    95.50

dtype: float64

Median Value for each Subject:

Acct    97.0

Eco     94.0

Eng     90.0

IP      94.0

Math    98.0

dtype: float64

>>> 

 

 

No comments:

Post a Comment