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"
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...
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:...
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.
USE PYTHON. Write a program that prompts the user to enter 5 test scores. The program...
USE PYTHON. Write a program that prompts the user to enter 5 test scores. The program should display a letter grade for each score and the average test score. Hint: Declare local variables under main() program Prompts the user to enter 5 test scores Define a function to calculate the average score: this should accept 5 test scores as argument and return the avg Define a function to determine the letter grade: this should accept a test score as argument...
1. Write an assembly language program that prompts the user for and reads four integers (x1,...
1. Write an assembly language program that prompts the user for and reads four integers (x1, y1, x2, y2) which represent the coordinates of two points. Make sure you keep track of which number is which. 2. Treat the line between the points as the radius of a sphere and compute the surface area of the sphere. Print the output with a label, such as “The surface area of the sphere is: …”. Hint: The distance between the points is...
Python program: Write a program that reads a text file named test_scores.txt to read the name...
Python program: Write a program that reads a text file named test_scores.txt to read the name of the student and his/her scores for 3 tests. The program should display class average for first test (average of scores of test 1) and average (average of 3 tests) for each student. Expected Output: ['John', '25', '26', '27'] ['Michael', '24', '28', '29'] ['Adelle', '23', '24', '20'] [['John', '25', '26', '27'], ['Michael', '24', '28', '29'], ['Adelle', '23', '24', '20']] Class average for test 1...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT