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

>>> 

 

 

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

>>> 

 

Class 12 IP Practical - 23

 

23. Consider the DataFrame (dfmks) given below.

 

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

WAP to print the maximum marks scored in a section, across all subjects.

import pandas as pd

import numpy as np

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

   'B':{'Acct':94.0,'Eco':94.0,'Eng':89.0,'IP':np.NaN,'Math':100.0}, \

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

   'D':{'Acct':97.0,'Eco':97.0,'Eng':89.0,'IP':95.0,'Math':np.NaN}}

 

dfmks=pd.DataFrame(d)

print("DataFrame is: ")

print(dfmks)

print("Maximum Marks in a section, across all subjects ")

print(dfmks.max(axis=0))

 

>>>

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

DataFrame is:

       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

Maximum Marks in a section, across all subjects

A     99.0

B    100.0

C     99.0

D     97.0

dtype: float64

>>> 

 

 

Class 12 IP Practical - 22

 

22. Consider the DataFrame (dfmks) given below.

 

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

WAP to print the maximum marks scored in each subject across all sections.

import pandas as pd

import numpy as np

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

   'B':{'Acct':94.0,'Eco':94.0,'Eng':89.0,'IP':np.NaN,'Math':100.0}, \

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

   'D':{'Acct':97.0,'Eco':97.0,'Eng':89.0,'IP':95.0,'Math':np.NaN}}

 

dfmks=pd.DataFrame(d)

print("DataFrame is: ")

print(dfmks)

print("Maximum Marks in each subject across all sections. ")

print(dfmks.max(axis=1))

 

 

 

>>>

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

DataFrame is:

       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

Maximum Marks in each subject across all sections.

Acct     99.0

Eco      97.0

Eng      95.0

IP       99.0

Math    100.0

dtype: float64

>>> 

Class 12 IP Practical - 21

 


21. WAP to  create a DataFrame to store weight, age and names of 3 people. Print the DataFrame and its transpose.

import pandas as pd

d={'Weight':[75,72,68],'Age':[25,23,21],'Name':['Ram','Raj','Sam']}

Df=pd.DataFrame(d)

print("DataFrame is : ")

print(Df)

print("Transpose of DataFrame is : ")

print(Df.T)

                     

 

>>>

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

DataFrame is :

   Weight  Age Name

0      75   25  Ram

1      72   23  Raj

2      68   21  Sam

Transpose of DataFrame is :

          0    1    2

Weight   75   72   68

Age      25   23   21

Name    Ram  Raj  Sam

>>>