DS2001 - Fall 2023 - Econ Practicum 7
.pdf
keyboard_arrow_up
School
Northeastern University *
*We aren’t endorsed by this school
Course
2001
Subject
Industrial Engineering
Date
Dec 6, 2023
Type
Pages
5
Uploaded by ElderSummer7952
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