Page 318 - Informatics_Practices_Fliipbook_Class12
P. 318
Practical
Solved
Program 1: Create a Pandas Series comprising exam scores of six subjects [85, 92, 78, 95, 88, 90]. Calculate the mean,
median, and standard deviation of the Series representing exam scores and provide a summary of the data.
Ans. import pandas as pd
scores = pd.Series([85, 92, 78, 95, 88, 90])
# Calculate mean, median, and standard deviation
meanScore = scores.mean()
medianScore = scores.median()
stdScore = scores.std()
print('Mean Score', meanScore)
print('Median Score', medianScore)
print('Standard Deviation', stdScore)
# Summary statistics
summary = scores.describe()
print('Summary', summary)
Program 2: Consider the following Pandas series storing temperature observed in day time over six consecutive days:
temperatures = pd.Series([25, 32, 28, 35, 30, 38])
Write a Python statement to extract all days observing temperatures above 30 degrees Celsius?
Ans. above30 = temperatures[temperatures > 30]
Program 3: Identify and count missing values in following Series representing exam scores:
scores = pd.Series([85, 92, None, 78, None, 90])
Ans. missingCount = scores.isnull().sum()
print('Number of missing values:', missingCount)
Program 4: Consider following two Series, one representing expenses and the other representing income:
expenses = pd.Series([500, 300, 200, 100])
income = pd.Series([2000, 1500, 2500, 1800])
Write a Python statement to calculate the net income.
Ans. import pandas as pd
expenses = pd.Series([500, 300, 200, 100])
income = pd.Series([2000, 1500, 2500, 1800])
304 Touchpad Informatics Practices-XII

