Page 103 - Informatics_Practices_Fliipbook_Class12
P. 103
c. dfFilledNaN = df.fillna(76)
print("DataFrame after filling NaN with 76:")
print(dfFilledNaN)
print("\n")
d. dfSetIndex = df.set_index("Name")
print("DataFrame with index set to Name:")
print(dfSetIndex)
print("\n")
e. averageMarksPerStudent = df.groupby(["Name", "Degree"])["Score"].mean()
print("Name and degree-wise average marks of each student:")
print(averageMarksPerStudent)
print("\n")
f. numStudentsInMBA = df[df["Degree"] == "MBA"].shape[0]
print("Number of students in MBA:", numStudentsInMBA)
print("\n")
g. modeMarksBCA = df[df["Degree"] == "BCA"]["Score"].mode().values
print("Mode marks in BCA:", modeMarksBCA)
Answers
Multiple Choice Questions
1. (a) 2. (b) 3. (a) 4. (c) 5. (a) 6. (c) 7. (a) 8. (a)
9. (a) 10. (a)
True or False
1. (T) 2. (F) 3. (F) 4. (T) 5. (F) 6. (T) 7. (F) 8. (T) 9. (F) 10. (T)
Fill in the blanks
1. pd.DataFrame() 2. pd.read_csv() 3. list / array 4. df.head(n)
5. header 6. loc 7. index 8. shape
9. dtypes 10. skiprows
Data Handling using Pandas DataFrame 89

