CBSE Class 12 Informatics Practices
Question 142 of 167
Python Pandas — I — Question 32
Back to all questions 32
Question Write a program in Python Pandas to create the following DataFrame batsman from a Dictionary :
| B_NO | Name | Score1 | Score2 |
|---|---|---|---|
| 1 | Sunil Pillai | 90 | 80 |
| 2 | Gaurav Sharma | 65 | 45 |
| 3 | Piyush Goel | 70 | 90 |
| 4 | Karthik Thakur | 80 | 76 |
Perform the following operations on the DataFrame :
(i) Add both the scores of a batsman and assign to column "Total".
(ii) Display the highest score in both Score1 and Score2 of the DataFrame.
(iii) Display the DataFrame.
import pandas as pd
data = {'B_NO': [1, 2, 3, 4], 'Name': ['Sunil Pillai', 'Gaurav Sharma', 'Piyush Goel', 'Karthik Thakur'], 'Score1': [90, 65, 70, 80], 'Score2': [80, 45, 90, 76]}
batsman = pd.DataFrame(data)
batsman['Total'] = batsman['Score1'] + batsman['Score2']
highest_score1 = batsman['Score1'].max()
highest_score2 = batsman['Score2'].max()
print("Highest score in Score1: ", highest_score1)
print("Highest score in Score2: ", highest_score2)
print(batsman)Highest score in Score1: 90
Highest score in Score2: 90
B_NO Name Score1 Score2 Total
0 1 Sunil Pillai 90 80 170
1 2 Gaurav Sharma 65 45 110
2 3 Piyush Goel 70 90 160
3 4 Karthik Thakur 80 76 156