subject
Engineering, 05.05.2020 23:07 ocean11618

Guidelines • You are not allowed to import anything. We know about the csv module, but you may not use it. • You are not allowed to use anything we haven't learned so far, including but not limited to: list comprehension, lambda functions, generators, builtins like zip(), etc. From built-in functions, you are not allowed to call sum(). Everything else is fair game. • You are allowed to use sets, dictionaries, and any of their respective operations. • You are allowed to use any string operations, including any way to format strings, except for string. find(), and string. replace() You can use any list operation, except for list. count() and list. sort() Do not hard code. Assignment The energy files are in the "csv" format, short for "comma separated values." These are just plain text files to represent a spreadsheet of information, where each piece of data is separated by a comma. The first row of each file is a description of what each column of information represents. Apart from the first column, the format of the header data is "Consumption. Sector. Energy" where Sector and Energy are replaced by one of several possible strings seen below. The possible economic sectors are (note the spaces): "Commercial", "Electric Power", "Industrial", "Refinery", "Residential", and "Transportation." The possible energy types are (note the spaces): "Coal", "Distillate Fuel Oil", "Geothermal", "Hydropower", "Kerosene", "Liquefied Petroleum Gases", "Other Petroleum Products", "Natural Gas", "Solar, "Wind", "Wood" State files A single state file contains the information for all years for the state given by the file name. Each line is one year's worth of comma separated data. The first line of a state file (the header) looks like this: Year, Consumption commercial. Coal 1, Consumption. Transportation. Natural Gas The header row tells you what each number in a particular line represents. The first number in a line of data in the state file is a year that data represents. The next number is the consumption in the "Commercial" sector for the "Coal" energy type. The last number in the line is the consumption in the "Transportation" sector for the "Natural Gas" energy type. The same idea applies to rest of the columns. Year files A single year file contains the information for all states for the year given by the file name. Each line is one state's worth of comma separated data. The first line of a year file (the header) looks like this: State, Consumption Commercial. coal,... Consumption. Transportation. Natural Gas The header row tells you what each number in a particular line represents, just like the state file. Functions The examples that you see here use the files that you are given to accompany this assignment. Make sure that when you test you either use the filename with a correct relative path to the csv file you are testing or you move the file you are testing to be in the same folder as your program. def summarize(filename): Description: Create a new file that contains a summary of the total consumption for three sectors: "Residential," "Commercial," and "Industrial." The summary is a per-line total of the consumption for all energy types of each sector. For each of the three sectors, calculate the sum of that sector's consumption in each line of the file. Write that sum to an output file in the appropriate column. You should write your output to a file, whose name is based on the original filename by adding "_summary" to the name. For example, if the input filename is "maryland. csv" then the output file should be called "maryland_summary. csv" The resulting file should have lines that look something like this (different for year files, where the leftmost column would be the states): Year, Consumption. Commercial, Consumption. Industrial, Consumption. Residential 1994,6787234,78849,610734 Parameters: filename, the name of an energy data file as described earlier. Return value: None, instead your result should be written to a file. Example output files for the following are included in the zipped files for this assignment. summarize('new_york. csv') < output in 'new_york_summary. csv' summarize('1977.csv') → output in '1977_summary. csv' summarize('virginia. csv') → output in 'virginia_summary. csv'

ansver
Answers: 1

Another question on Engineering

question
Engineering, 03.07.2019 14:10
The y form of iron is known as: a) ferrite b) cementite c) perlite d) austenite
Answers: 3
question
Engineering, 03.07.2019 15:10
Heat is added to a piston-cylinder device filled with 2 kg of air to raise its temperature 400 c from an initial temperature of t1 27 cand pressure of pi 1 mpa. the process is isobaric process. find a)-the final pressure p2 b)-the heat transfer to the air.
Answers: 1
question
Engineering, 04.07.2019 18:10
The higher the astm grain size number, the finer the gran is. a)-true b)-false
Answers: 2
question
Engineering, 04.07.2019 18:10
What are the two (02) benefits, which may result from a successful implementation of preventive maintenance (pm) program in an organization? (clo3)a)- lean manufacturing b)-overlapping responsibilities c)-the planner is not qualified d)-accurate contractor information e)-reduction in equipment redundancies f)-accurate stores information
Answers: 3
You know the right answer?
Guidelines • You are not allowed to import anything. We know about the csv module, but you may not u...
Questions
question
Health, 22.02.2021 19:40
question
Arts, 22.02.2021 19:40
question
History, 22.02.2021 19:40
question
Biology, 22.02.2021 19:40
question
Spanish, 22.02.2021 19:40
question
Mathematics, 22.02.2021 19:40
question
Mathematics, 22.02.2021 19:40
Questions on the website: 13722366