Thursday, 11 March 2021

Class 12 IP Practical - 24

 

24. WAP to calculate mode for each subject and each section 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("Mode Value for each subject: ")

print(dfmks.mode(axis=1))

print("Mode Value for each Section: ")

print(dfmks.mode(axis=0))

 

 

RESTART: C:/Program Files (x86)/Python38-32/IP-24.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

Mode Value for each subject:

       0

Acct  97

Eco   94

Eng   89

IP    94

Math  99

Mode Value for each Section:

      A     B   C     D

0  94.0  87.0  92  97.0

1   NaN   NaN  99   NaN

>>> 

 

No comments:

Post a comment