Page 320 - Informatics_Practices_Fliipbook_Class12
P. 320
Program 8: Consider the following series comprising the health data for two individuals, Person A and Person B. The
data includes the daily recorded number of steps taken by each person over a week:
personASteps = pd.Series([8000, 7500, 9000, 6000, 5500, 10000, 7000])
personBSteps = pd.Series([6000, 8500, 7000, 8000, 7500, 9000, 9500])
Write a Python code snippet for the following:
(i) Determine the highest and lowest number of steps taken by Person A.
(ii) Find the day(s) when Person A has taken more than 7000 steps.
(iii) Calculate the average number of steps for both Person A and Person B.
(iv) Count the number of days on which Person B took more steps than Person A.
(v) Identify the days on which Person A took fewer than 6000 steps.
Data:
Ans. (i) maxStepsA = personASteps.max()
minStepsA = personASteps.min()
print('Maximum Number of Steps:', maxStepsA)
print('Minimum Number of Steps:', minStepsA)
(ii) days = personASteps[personASteps >7000]
print('Days when Person A has taken more than 7000 steps', days)
(iii) avgStepsA = personASteps.mean()
avgStepsB = personBSteps.mean()
print('Average Number of Steps by A:', avgStepsA)
print('Average Number of Steps by B:', avgStepsB)
(iv) daysCount = (personBSteps > personASteps).sum()
print('number of days on which Person B took more steps than Person A:',
daysCount)
(v) days = personASteps[personASteps < 6000]
print('Days when Person A took fewer than 6000 steps:', days)
Program 9: Consider the following weather data for a week stored in the form of a dictionary:
weatherData = {
'Date': ['2023-01-01', '2023-01-02', '2023-01-03', '2023-01-04', '2023-01-05'],
'Temperature': [15.0, 14.5, 16.2, 13.8, 15.5],
'Humidity': [50, 52, 48, 55, 51],
'Wind_Speed': [10, 12, 9, 11, 13]
}
(i) Create a DataFrame weatherDF from the provided dictionary.
(ii) Retrieve and display the data for the second day (2023-01-02) using loc.
306 Touchpad Informatics Practices-XII

