Homework Project #4: Using Pivot Tables
Objective: To apply knowledge about Pivot Tables to analyze data.
Dataset: For this assignment, you will use the happiness dataset that contains panel data with country and years related to the happiness index. The dataset is described in Appendix 1.
Requirements: Using the variable assigned “freedom to make life choices” & your Python code should do the following (See sample output on Appendix 2).
1. Reduce your dataset to the last four years XXXXXXXXXXand keep all the variables. Add code to answer how many rows and columns are in the reduced dataset, and whether your variable has any missing values.
2. Calculate the average of your assigned variable for all countries across the four-year period. Sort the dataset to show first the countries with the highest values.
3. Calculate the median of your assigned variable by region.
4. Calculate the mean of the variable by region and year and graphically show how the variable has changed.
Code Documentation: The first line of your Python code should include a comment with your name, course section and date. You should also include other comments in your program explaining your code, variable names, or approaches.
Submit for grading: For this assignment, you need to upload two files: a plain text file (.txt) with your documented Python code, and a Word document (.doc) with screenshots of Jupyter notebook runs and results. For this assignment, you need to write a paragraph in your Word document analyzing this variable based on the results of your tables (#2-#4 above).
Grading Ru
ic: 20% independent verification of program run; 50% required and co
ect output; 20% file submission compliance; 10% authorship, code, and printout documentation.
Appendix 1: Data Set Description
Six key variables are combined to form the happiness score index calculated for each country:
· Economy: Log GDP per capita
· Family: social support
· Health: healthy life expectancy at birth
· Freedom: freedom to make life choices
· Generosity: perceptions of generosity
· Trust: perceptions of co
uption
The “Life Ladder” is the main life evaluation question, where 10 is the best possible life and 0 is the worst. You can read more about this at: https:
worldhappiness.report/ed/2021
Appendix 2: Sample Output (for the Life Ladder Variable)
Q1: Characteristics of reduced dataset and missing values on Life Ladde
Q2: Average by country with sorted results
Q3: Median by Region and Year
Q4: Mean by Region and Year in Table and Graph