Page 319 - Informatics_Practices_Fliipbook_Class12
P. 319
# Calculate net income
netIncome = income - expenses
print('Net Income:', netIncome)
Program 5: Consider the following two Series, basicIncome and travelAllowance comprising basic income
and travel allowances of five employees in the company.
basicIncome = pd.Series([3000, 3500, 4000, 3200, 3700])
travelAllowance = pd.Series([500, 600, 400, 450, 550])
Write a Python statement to calculate total income.
Ans. import pandas as pd
basicIncome = pd.Series([3000, 3500, 4000, 3200, 3700])
travelAllowance = pd.Series([500, 600, 400, 450, 550])
# Calculate the totalIncome
totalIncome = basicIncome + travelAllowance
print('Total Income:', totalIncome)
Program 6: Create a Series from the following dictionary where the keys represent different educational streams, and
the values represent the corresponding program enrollment numbers:
data = {'Science': 1103, 'Commerce': 1104, 'Arts': 1105}
Ans. import pandas as pd;
data = {'Science': 1103, 'Commerce': 1104, 'Arts': 1105}
streamsEnrollmentNum = pd.Series(data)
print('Streams Enrollment Number: ', streamsEnrollmentNum)
Program 7: Consider the following series object comprising gender details of students in class XII.
genderXII = pd.Series(['M', 'F', 'M', 'M', 'M', 'F', 'F', 'M', 'M'])
Write the Python statement to calculate the gender distribution ratio of male to female students in the class.
Ans. genderXII = pd.Series(['M', 'F', 'M', 'M', 'M', 'F', 'F', 'M', 'M'])
# Calculate the count of male and female students
maleCount = (genderXII == 'M').sum()
femaleCount = (genderXII == 'F').sum()
# Calculate the gender distribution ratio
genderRatio = maleCount / femaleCount
print('Gender Distribution Ratio:', genderRatio)
Practical 305

