In: Computer Science
Question:
Write a program in python that reads in the file climate_data_2017_numeric.csv and prompts the user to enter the name of a field (other than Date), and then outputs the highest and lowest values recorded in that field for the month of August.
The file climate_data_2017_numeric.csv contains the following fields:
Expected print out output (Make sure your output looks exactly like the output shown):
Note: there are 2 space in front of the last line.
Available field names:
Minimum temperature (C)
Maximum temperature (C)
Rainfall (mm)
Speed of maximum wind gust (km/h)
9am Temperature (C)
9am relative humidity (%)
3pm Temperature (C)
3pm relative humidity (%)
Please enter a field name: Minimum temperature (C)
Statistics for field 'Minimum temperature (C)':
Min: 1.0 Max: 14.6
Dataset:
https://docs.google.com/spreadsheets/d/1MjyOSUrm2Nazo9vpan_4E6fAhQlr8Ok2PXu9c8syXqY/edit?usp=sharing
print("Available field names:");
is_first_line=True;
l1=[];
f=open("climate_data_2017_numeric.csv");
lines=f.readlines();
data_by_august=[];
fieldnames=[];
for line in lines:
if is_first_line:
for name in line.split(',')[1:]:
print(name.strip());
fieldnames.append(name);
is_first_line=False;
else:
values=line.split(',');
date=values[0];
month=date.split("-")[1];
if month=='08':
key=values[0];
data_by_august.append(values[1:]);
requested_field=input("Please enter a field name: ");
print("Statistics for field '"+requested_field+"':");
for data in data_by_august:
#print(key);
field=data[fieldnames.index(requested_field)];
l1.append(float(field));
print(" Min:",min(l1),"Max:",max(l1));
Expected output:
Available field names: Minimum temperature (c) Maximum temperature (C) Rainfall (mm) Speed of maximum wind gust (km/h) 9am Temperature (C) 9am relative humidity (%) 3pm Temperature (C) 3pm relative humidity (%) Please enter a field name: Minimum temperature (C) Statistics for field 'Minimum temperature (C)': Min: 1.0 Max: 14.6