Page 86 - Informatics_Practices_Fliipbook_Class12
P. 86
Case-based Questions
Suppose, Arush working in meteorological department wishes to retrieve and analyze the weather data for first five days
of a week. Thus, he gathered the data and stored it in the form of following 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]
}
Help Arun by writing Python statements to store the dictionary in form of a DataFrame so that he can retrieve the following
information for the analysis:
a. Retrieve and display the data for the second day (2023-01-02)
b. Retrieve and display the temperature and humidity data for the first three days.
c. Retrieve and display the wind speed data for the last two days.
d. Retrieve rows with Temperature greater than 15.
e. Retrieve rows where Humidity is greater than 50.
f. Retrieve the summary statistics of the DataFrame.
g. Determine the maximum wind speed.
Ans. weatherDF = pd.DataFrame(weatherData)
print(weatherDF)
a. data = weatherDF.loc[1]
print('Data for the second day (2023-01-02):')
print(data)
b. data = weatherDF.loc[0:2, ['Date', 'Temperature', 'Humidity']]
print('Temperature and humidity data for the first three days:')
print(data)
c. print('Wind speed data for the last two days')
print(weatherDF.iloc[-2:][['Date', 'Wind_Speed']])
d. # Retrieve rows with Temperature greater than 15
print("\nRows with Temperature greater than 15:")
print(weatherDF[weatherDF['Temperature'] > 15])
e. # Retrieve rows where Humidity is greater than 50
print("\nRows where Humidity is greater than 50:")
print(weatherDF[weatherDF['Humidity'] > 50])
f. # Retrieve the summary statistics of the DataFrame
print("\nSummary statistics of the DataFrame:")
print(weatherDF.describe())
g. # Determine the maximum wind speed
maxWindSpeed = weatherDF['Wind_Speed'].max()
72 Touchpad Informatics Practices-XII

