Question

Question 2 (10 points) (quality.py): We are provided with data from a quality control process in a manufacturing firm. The daAverage: 149.08 Standard deviation: 145.42 c. Develop a function called print_area_stats that accepts two parameters, list of

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import statistics
from collections import defaultdict

def write_area_measures(area, area_list, value_list):
    file_name = area + "_data.csv"
    with open(file_name, 'w') as write_file:
        for area_val, value in zip(area_list, value_list):
            if(area_val.strip() == area.strip()):
                write_file.write(str(value)+ "\n")


def print_area_stats(area_list, value_list):
    area_dict = defaultdict(list)

    for area,value in zip(area_list,value_list):
        area_dict[area].append(value)

    for area in area_dict.keys():
        print("\nArea : ", area)
        print_overall_stats(area_dict[area])


def print_overall_stats(value_list):
    print("Overall Statistics")
    print("\t Count: ", len(value_list))
    print("\t Maximum: ", min(value_list))
    print("\t Minimum: ", max(value_list))
    print("\t Average: ", round( (sum(value_list) / len(value_list) ) , 2 ) )
    if(len(value_list) == 1 ):
        print("\t Standard Deviation: ", 0)
    else:
        print("\t Standard Deviation: ", round(statistics.stdev(value_list), 2))



def load_data(filename):
    areas = []
    values = []
    with open(filename) as f:
        for line in f:
            line = line.replace("\n","")
            areas.append(line.split(",")[0])
            values.append(int(line.split(",")[1]))
    return (areas,values)



if __name__ == "__main__":
    (area_list, value_list) = load_data("data.csv")
    print_overall_stats(value_list)
    print_area_stats(area_list, value_list)
    write_area_measures("Montreal", area_list, value_list)

CODE:

quality.py data.csv import statistics 1 from collections import defaultdict 2 31 def write_area measures (area, area list, va

data.csv File

quality.py data.csv Montreal,122 1 Ottawa, 242 Calgary, 182 Montreal, 926 Montreal, 213 Ottawa, 543 Ottawa, 663 7 8 st

Output:

Run: quality C:Anacondalenvs\Pycharm_env\python.exe C:/Users/Sanchit Kumar/PycharmProjects/untitledl/quality.py Overall Sta

Add a comment
Know the answer?
Add Answer to:
Question 2 (10 points) (quality.py): We are provided with data from a quality control process in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Description: Create a program called numstat.py that reads a series of integer numbers from a file...

    Description: Create a program called numstat.py that reads a series of integer numbers from a file and determines and displays the name of file, sum of numbers, count of numbers, average of numbers, maximum value, minimum value, and range of values. Purpose: The purpose of this challenge is to provide experience working with numerical data in a file and generating summary information. Requirements: Create a program called numstat.py that reads a series of integer numbers from a file and determines...

  • The name of the C++ file must be search.cpp Write a program that will read data...

    The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...

  • Please help with this code For the following problem write a Matlab® script file with clear...

    Please help with this code For the following problem write a Matlab® script file with clear commentary for each line of code. Your script should: Load the data in the problem as a text file. Calculate the statistics using Matlab  functions. Solicit input from the user of the reading (for example, 137 degrees as stated in the problem). In another word, the reading should not be fixed in the script and has to be entered and saved from the command window...

  • A csv file called COS-206_gradebook.csv is provided for this project (see Course Documents). This file contains...

    A csv file called COS-206_gradebook.csv is provided for this project (see Course Documents). This file contains grades data for 17 students on 20 assessments. These assessments include quizzes, homework assignments, term projects, and tests.First you are strongly encouraged to open this file in Excel to gain an overview of the data. Note the second row contains point totals for the assessments. For instance, the point total for hw0 (Homework 0) is 20 while the point total for hw1 (Homework 1)...

  • Could anyone help add to my python code? I now need to calculate the mean and...

    Could anyone help add to my python code? I now need to calculate the mean and median. In this programming assignment you are to extend the program you wrote for Number Stats to determine the median and mode of the numbers read from the file. You are to create a program called numstat2.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The...

  • INTRODUCTION You are working on development of a new power plant for Centerville, USA. Average monthly...

    INTRODUCTION You are working on development of a new power plant for Centerville, USA. Average monthly temperature data has been collected as part of designing the new power plant, and you are required to develop a computer program that will perform averaging analysis. The input data file is called temp. As you examine the input file, you notice that the first record line is the name of the city and type of data, the second record line contains the control...

  • Need help on C++ (User-Defined Function) Format all numerical decimal values with 4 digits after ...

    need help on C++ (User-Defined Function) Format all numerical decimal values with 4 digits after the decimal point. Process and sample run: a) Function 1: A void function that uses parameters passed by reference representing the name of a data file to read data from, amount of principal in an investment portfolio, interest rate (any number such as 5.5 for 5.5% interest rate, etc.) , number of times the interest is compounded, and the number of years the money is...

  • In the lectures about lists we have seen some Python code examples that involve the processing of...

    In the lectures about lists we have seen some Python code examples that involve the processing of lists containing weather statistics. The original source of the values shown in the slides was taken from part of the Environment Canada website that serves up historical data: http://climate.weather.gc.ca/historical_data/search_historic_data_e.html    Data can be provied by that website using the Comma Separated Value (CSV) format which is stored in text files normally using a CSV suffix. We will not work directly with such files in...

  • Homework 2 Description This homework will test the use of arrays and control structures. In summary,...

    Homework 2 Description This homework will test the use of arrays and control structures. In summary, you will read 10 integers from standard input, store them into an array and then produce some statistics. Details You need to compute Array Statistics. Create a class called Hwk2 that implements a main to solve your homework. At the beginning display a line with the following text: Type 10 integer values: Then, read 10 integers from standard input, one by one and store...

  • Help me with this Python Question a. build_word_dictionary (filename) – This builds a word dictionary indexed...

    Help me with this Python Question a. build_word_dictionary (filename) – This builds a word dictionary indexed by words from the file who’s filename is provided as an argument. It uses the words as keys and the count of occurrences as values. It returns the dictionary it constructed. It can use the ‘tokenize()’ function that is provided in the lecture slides. b. inverse_dict(dict) – This method takes a dictionary (generated by build_word_dictionary() and inverts it (as was done with students and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT