Programs · Program 4-10
Q.(Program 4-10) Consider the open dataset "Seasonal and Annual Min/Max Temp Series - India from 1901 to 2017" from data.gov.in (file "Min_Max_Seasonal_IMD_2017.csv"). The aim is to plot the minimum and maximum temperature and observe the number of times (frequency) a particular temperature has occurred. Extract only the 'ANNUAL - MIN' and 'ANNUAL - MAX' columns from the file and display two Histogram plots:
(i) only for 'ANNUAL - MIN'
(ii) for both 'ANNUAL - MIN' and 'ANNUAL - MAX' (with x axis labelled 'Temperature' and y axis 'Number of times').
Yanam BieapTextbookSubjective· 4mImportance★★★★★est
30% · 13/44 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Read only the two temperature columns needed, then plot each as its own histogram.
import pandas as pd
import matplotlib.pyplot as plt
data=pd.read_csv("Min_Max_Seasonal_IMD_2017.csv", usecols=['ANNUAL - MIN','ANNUAL - MAX'])
df=pd.DataFrame(data)
df.plot(kind='hist',y='ANNUAL - MIN',title='Annual Minimum Temperature (1901-2017)')
plt.xlabel('Temperature')
plt.ylabel('Number of times')
df.plot(kind='hist',title='Annual Min and Max Temperature (1901-2017)',color=['blue','red'])
plt.xlabel('Temperature')
plt.ylabel('Number of times')
plt.show()
usecols=[...] at read time keeps only the two needed columns; df.plot(kind='hist', ...) builds the histogram directly, without arbitrary manual bin counts.
Step by step
usecols=['ANNUAL - MIN','ANNUAL - MAX']filters the columns AT READ TIME, so pandas never even loads the dataset's other seasonal columns (JAN-FEB, MAR-MAY, etc.) into memory -- useful since the real IMD file spans 1901-2017, a long time series with many columns this question doesn't need.- The first
df.plot(kind='hist', y='ANNUAL - MIN', ...)call restricts the plot …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.