DS2001 - Fall 2023 - Econ Practicum 7

pdf

School

Northeastern University *

*We aren’t endorsed by this school

Course

2001

Subject

Industrial Engineering

Date

Dec 6, 2023

Type

pdf

Pages

5

Uploaded by ElderSummer7952

Report
DS2001 - Economics Practicum Practicum 7 - Dictionary Fall 2023 Oct 24, 2023 Deadline: Oct 25, 2023 at 12:00 noon Boston time via Gradescope Gradescope for DS2001-15008: https://www.gradescope.com/courses/601852 Gradescope for DS2001-15009: https://www.gradescope.com/courses/601858 We’ll be working in pairs this week! With your partner, work on the programming assignment below. We add a Self-Reflection portion at the end! It is optional , but if you are not 100% sure about your code, you may achieve extra credit by answering questions in self-reflection. What you're turning in today: p7py (and p7.pdf for self-reflection) Grading Policy: You can complete the assignment individually or in pairs. Have one person in your group submit your code to gradescope. Each practicum is evaluated on a scale of 0-5, based on the completion of your code and answers on self-reflection. This practicum will be included in your final score. If you miss practicum this week: Fill out the " missing class form " ASAP. Today’s Goals Create a dictionary Create a bar chart from a dictionary More time on Project Proposal Working in Pairs Each pair will work at one computer, and everyone contributes. Here’s how we split up the work: Navigator: Dictates the code to be written. Explains the why as we go. Checks for syntax errors.
Driver: Writes the code. Listens closely to the navigator. Asks questions whenever there is a lack of clarity. Both driver and navigator are responsible for contributing to the work, and for making space for the other person to make contributions. Programming Assignment Write your file comment, your main(), and import the matplotlib module, like we did last time. This is a good habit to get into for all your programs! Happiest States Today we’ll look at Happiest States in 2022. The dataset is from World Population Review , which provides interesting statistics on world population. 50 states were compared across three key dimensions: 1) Emotional & Physical Well-Being, 2) Work Environment and 3) Community & Environment.You can read in detail about the dataset here: https://wallethub.com/edu/happiest-states/6959 ,including descriptions of how the rank is generated. The data format is: (a) The first column, state , is the name of each state in the US. (b) The second column, score , is the happiness score. (c) The third column, lovejob , is the measurement of job satisfaction, and takes three values: Yes, Fair, No. Task 0: Gather data Download happystate.csv from Canvas. Save the file in the same folder as the Python program p7.py you’ll be writing. Task 1: Lists to Dictionary Write a function that takes as input a csv filename, and returns the first two columns of the data in that file as a dictionary (i.e. state is the key, and score is the value). In main, call this function to read in happystate.csv , and save the result. Hint: Read the first two columns of the csv file into two lists, and join the two lists to a dictionary using zip() function.
""" name: read_data_dict This function takes a file name and returns a dictionary such that the key is the first column and the value is the second column of the file. parameters: File name return: A dictionary """ Task 2: Find the State Write a function that asks the user the state name, and print out the corresponding happiness score. In main, call this function. """ name: findstate This function takes a dictionary and prints out the value given the key from the user. parameters: Dictionary return: None """ Example output: Task 3: Statistics on Job Love 1. Write a function that takes the filename as input, and reads the third column in the file lovejob into a list.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
""" name: read_data_list This function takes the file name and returns the third column as a list. parameters: File name return: A list """ 2. Write a function for the word count on the list you get from the third column. Generate a dictionary that counts the frequency of each level of job satisfaction. The keys in the dictionary should be job love level (Yes, Fair, No) , and the values should be frequency. (You can find an example code of word count in DS2000 lecture or py7lec.py in DS2001) """ name: countword This function takes a list and returns a dictionary in which the key is the element in the list and the value is the frequency. parameters: A list return: A dictionary """ 3. Write a function that generates a barchart from a dictionary. The keys in the dictionary should be bar names (job love level Yes, Fair, No) , and the values should be bar values. Call this function in main to create a chart of job love level and their frequency. """ name: plotbar This function takes a dictionary and shows a bar chart of the dictionary. parameters: dictionary return: Bar plot with keys on x-axis, and values on y-axis. """ Hint: To plot keys on x-axis, you can put them as 1, 2 ,3 and use plt.xticks to edit them as Yes, Fair, No. Call the above three functions in main to generate the dictionary plot the barchart of job love level.
Self-Reflection Create a PDF with answers to the following questions (each should be answered collaboratively with your partner unless instructed otherwise): Does this work reflect the best effort of both partners? In what way(s) did each partner (1) make contributions to the assignment, and (2) give the other person space to make contributions? (Each partner should respond to this question separately.) Which problem(s) would you like feedback on and why?