Question

In: Computer Science

Question: Write a program in python that reads in the file climate_data_2017_numeric.csv and prompts the user...

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:

  1. Date
  2. Minimum temperature (C)
  3. Maximum temperature (C)
  4. Rainfall (mm)
  5. Speed of maximum wind gust (km/h)
  6. 9am Temperature (C)
  7. 9am relative humidity (%)
  8. 3pm Temperature (C)
  9. 3pm relative humidity (%)

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

Solutions

Expert Solution

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


Related Solutions

1. Write a program that prompts the user for a filename, then reads that file in...
1. Write a program that prompts the user for a filename, then reads that file in and displays the contents backwards, line by line, and character-by character on each line. You can do this with scalars, but an array is much easier to work with. If the original file is: abcdef ghijkl the output will be: lkjihg fedcba Need Help with this be done in only PERL. Please use "reverse"
In Python write a program that prompts the user for a file name, make sure the...
In Python write a program that prompts the user for a file name, make sure the file exists and if it does reads through the file, count the number of times each word appears and then output the word count in a sorted order from high to low. The program should: Display a message stating its goal Prompt the user to enter a file name Check that the file can be opened and if not ask the user to try...
C++ Write a program that prompts for a file name and then reads the file to...
C++ Write a program that prompts for a file name and then reads the file to check for balanced curly braces, {; parentheses, (); and square brackets, []. Use a stack to store the most recent unmatched left symbol. The program should ignore any character that is not a parenthesis, curly brace, or square bracket. Note that proper nesting is required. For instance, [a(b]c) is invalid. Display the line number the error occurred on. These are a few of the...
Write a Python program that reads a file, input by the user, containing one word/token per...
Write a Python program that reads a file, input by the user, containing one word/token per line with an empty line between sentences. The program prints out the longest word found in the file along with its length.
Write a program that prompts the user to enter a file name, then opens the file...
Write a program that prompts the user to enter a file name, then opens the file in text mode and reads names. The file contains one name on each line. The program then compares each name with the name that is at the end of the file in a symmetrical position. For example if the file contains 10 names, the name #1 is compared with name #10, name #2 is compared with name #9, and so on. If you find...
all python Question One [2 * 2.5] Write a program that prompts the user for two...
all python Question One [2 * 2.5] Write a program that prompts the user for two integers and then prints •The sum •The difference •The product •The average •The distance (absolute value of the difference) •The maximum (the larger of the two) •The minimum (the smaller of the two) Hint: Python defines max and min functions that accept a sequence of values, each separated with a comma. Write a program that prompts the user for a measurement in meters and...
Question 1: Write a Java program that prompts the user to input a file name (existing...
Question 1: Write a Java program that prompts the user to input a file name (existing text file), then calculate and display the numbers of lines in that file. Also calculate and display the length of the longest line in that file. For example, if the input file has the following lines: Hello This is the longest line Bye The output should be: The file has 3 lines. The longest line is line 2 and it has 24 characters. Test...
Write a program that prompts the user for a file name, make sure the file exists...
Write a program that prompts the user for a file name, make sure the file exists and if it does reads through the file, count the number of times each word appears and then output the word count in a sorted order from high to low. The program should: Display a message stating its goal Prompt the user to enter a file name Check that the file can be opened and if not ask the user to try again (hint:...
Write a program that prompts the user for a file name, make sure the file exists...
Write a program that prompts the user for a file name, make sure the file exists and then reads through the file, counts the number of times each word appears and outputs the word count in a sorted order from high to low. The program should: Display a message stating its goal Prompt the user to enter a file name Check that the file can be opened and if not ask the user to try again (hint: use the try/except...
Python: Write a program that asks the user for the name of a file. The program...
Python: Write a program that asks the user for the name of a file. The program should display the contents of the file line by line.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT