Page 92 - Informatics_Practices_Fliipbook_Class12
P. 92
(ii) #Method 1
player.rename(columns={'points':'netpoint'},inplace=True)
#Method 2
player.columns=['pid','pname','sports','netpoints']
5. Consider the given DataFrame 'health'. [2023]
Diseasename Agent
0 Common Cold Virus
1 Chickenpox Virus
2 Cholera Bacteria
3 Tuberculosis Bacteria
Write suitable Python statements for the following:
(i) Remove the row containing details of disease named Tuberculosis.
(ii) Add a new disease named 'Malaria' caused by 'Protozoa'.
(iii) Display the last 2 rows.
Ans. (i) health.drop(health[health['Diseasename']=='Tuberculosis'].
index,inplace=True) or health=health.
loc[health["Diseasename"]!='Tuberculosis'] or
health=health.query("Diseasename!='Tuberculosis'") or
health=health[health["Diseasename"]!='Tuberculosis']
(ii) health.loc[len(health)]=['Malaria','Protozoa'] or
health=health.append({'Diseasename':'Malaria','Agent':'Protozoa'}, ignore_ index=True)
(iii) print(health.tail(2)) or print(health.iloc[-2:]) or print(health[-2:]) or
print(health.loc[len(health)-2:])
6. Consider the following DataFrame 'mdf'. [2023]
Rollno Name English Hindi Maths
0 1 Aditya 23 20 28
1 2 Balwant 18 1 25
2 3 Chirag 27 23 30
3 4 Deepak 11 3 7
4 5 Eva 17 21 24
a. Write Python statements for the DataFrame 'mdf':
(i) To display the records of the students having roll numbers 2 and 3
(ii) To increase the marks of subject Math by 4, for all students.
b. Write Python statement to display the Rollno and Name of all students who secured less than 10 marks in Maths.
OR
(Option for part (b) only)
Write Python statement to display the total marks i.e. sum of marks secured in English, Hindi, and Maths for all students.
Ans. a. (i) print(mdf[1:3]) or print(mdf.iloc[1:3]) or print(mdf.loc[1:2])
(ii) mdf['Maths']=mdf['Maths']+4 or mdf.Maths=mdf.Maths+4
b. print(mdf.loc[(mdf['Maths']<10),['Rollno','Name']])
OR
s_cols=mdf.sum(numeric_only=True,axis=0)
print(s_cols[1:])
78 Touchpad Informatics Practices-XII

