Question

In: Computer Science

In python, Here's some fake data. df = {'country': ['US', 'US', 'US', 'US', 'UK', 'UK', 'UK'],...

In python,

Here's some fake data.

df = {'country': ['US', 'US', 'US', 'US', 'UK', 'UK', 'UK'],
   'year': [2008, 2009, 2010, 2011, 2008, 2009, 2010],
   'Happiness': [4.64, 4.42, 3.25, 3.08, 3.66, 4.08, 4.09],
   'Positive': [0.85, 0.7, 0.54, 0.07, 0.1, 0.92, 0.94],
   'Negative': [0.49, 0.09, 0.12, 0.32, 0.43, 0.21, 0.31],
   'LogGDP': [8.66, 8.23, 7.29, 8.3, 8.27, 6.38, 6.09],
   'Support': [0.24, 0.92, 0.54, 0.55, 0.6, 0.38, 0.63],
   'Life': [51.95, 55.54, 52.48, 53.71, 50.18, 49.12, 55.84],
   'Freedom': [0.65, 0.44, 0.06, 0.5, 0.52, 0.79, 0.63, ],
   'Generosity': [0.07, 0.01, 0.06, 0.28, 0.36, 0.33, 0.26],
   'Corruption': [0.97, 0.23, 0.66, 0.12, 0.06, 0.87, 0.53]}

I have a list of happiness and six explanatory vars.
exp_vars = ['Happiness', 'LogGDP', 'Support', 'Life', 'Freedom', 'Generosity', 'Corruption']

1. Define a variable called explanatory_vars that contains the list of the 6 key explanatory variables

2. Define a variable called plot_vars that contains Happiness and each of the explanatory variables. (Hint: recall that you can concatenate Python lists using the addition (+) operator.)

3. Using sns.pairplot, make a pairwise scatterplot for the WHR data frame over the variables of interest, namely the plot_vars. To add additional information, set the hue option to reflect the year of each data point, so that trends over time might become apparent. It will also be useful to include the options dropna=True and palette='Blues'.

Solutions

Expert Solution

import seaborn as sns

import pandas as pd

df = {'country': ['US', 'US', 'US', 'US', 'UK', 'UK', 'UK'],

   'year': [2008, 2009, 2010, 2011, 2008, 2009, 2010],

   'Happiness': [4.64, 4.42, 3.25, 3.08, 3.66, 4.08, 4.09],

   'Positive': [0.85, 0.7, 0.54, 0.07, 0.1, 0.92, 0.94],

   'Negative': [0.49, 0.09, 0.12, 0.32, 0.43, 0.21, 0.31],

   'LogGDP': [8.66, 8.23, 7.29, 8.3, 8.27, 6.38, 6.09],

   'Support': [0.24, 0.92, 0.54, 0.55, 0.6, 0.38, 0.63],

   'Life': [51.95, 55.54, 52.48, 53.71, 50.18, 49.12, 55.84],

   'Freedom': [0.65, 0.44, 0.06, 0.5, 0.52, 0.79, 0.63, ],

   'Generosity': [0.07, 0.01, 0.06, 0.28, 0.36, 0.33, 0.26],

   'Corruption': [0.97, 0.23, 0.66, 0.12, 0.06, 0.87, 0.53]}

dataFrame = pd.DataFrame.from_dict(df)

explanatory_vars = ['LogGDP', 'Support', 'Life', 'Freedom', 'Generosity', 'Corruption']

plot_vars = ['Happiness'] + explanatory_vars

sns.pairplot(dataFrame,

             x_vars = explanatory_vars,

             dropna=True,

             palette="Blues")    

----------------------------------------------------------------------------------------------------
Your ThumbsUp on this answer matters to me a lot :)
----------------------------------------------------------------------------------------------------
For any further clarifications, Please do not hesitate to reach out in the comments section


Related Solutions

Collect data on inflation and unemployment for the UK and the US during the 1970s and...
Collect data on inflation and unemployment for the UK and the US during the 1970s and 1980s using OECD.stat. The 1980s was a period of significant disinflation for the two economies. Use the data gathered* and content of the chapter 4 of the textbook to answer the following questions: a. Was the disinflation costly in terms of unemployment? b. Does the data provide evidence that inflation expectations were being formed rationally during this period? c. How can the concept of...
Which is the optimal return combination for both the US/UK and US Spain? US UK SPAIN...
Which is the optimal return combination for both the US/UK and US Spain? US UK SPAIN CH13 INTERNATIONAL PORTFOLIO DIVERSIFICATION ANALYSIS ER 15% 12% 5% DEVELOPED VS EMERGING MARKET DIVERSIFICATION STD 10% 9% 4% CAN-β= CAN$ rose by COL Peso fell by CORR 1 0.33 0.06 COL-β= US&CAN* $Ret= US&COL* $Ret CV 1.5 1.3333 1.25 Weights W1 100% 90% 80% 70% 60% 50% 40% 30% 20% 10% 0% W2 0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%...
with python, create a fake logo for a company using turtle graphics
with python, create a fake logo for a company using turtle graphics
What does Uk < Us mean?
What does Uk < Us mean?
In Python I have a code: here's my problem, and below it is my code. Below...
In Python I have a code: here's my problem, and below it is my code. Below that is the error I received. Please assist. Complete the swapCaps() function to change all lowercase letters in string to uppercase letters and all uppercase letters to lowercase letters. Anything else remains the same. Examples: swapCaps( 'Hope you are all enjoying October' ) returns 'hOPE YOU ARE ALL ENJOYING oCTOBER' swapCaps( 'i hope my caps lock does not get stuck on' ) returns 'I...
"Python lists are power data structures. Describe some of the benefits of Python lists" Answer the...
"Python lists are power data structures. Describe some of the benefits of Python lists" Answer the question above in a few sentences.
"Python lists are power data structures. Describe some of the benefits of Python lists" Make sure...
"Python lists are power data structures. Describe some of the benefits of Python lists" Make sure you don't just give me a list but a few sentences instead just answering it.
describe to us what big data is and share with us an example? What are some...
describe to us what big data is and share with us an example? What are some ethical considerations in how the data was gathered and how it might be used for research or other purposes? What about big data makes these considerations similar or different to data obtained through traditional real-world experimental methods?
For the US and the country you have chosen, gather data on inflation rates for the...
For the US and the country you have chosen, gather data on inflation rates for the most recent three years that are available. Please make sure that you note the specific price index that you are using and provide a description of the characteristics of that index, particularly for the country you have selected. Please make sure that you fully explain the information you are providing. What has happened to prices and how has this affected the broader economy; is...
Starting out with python Lists and Tuples - US Population Data In this assignment, you will...
Starting out with python Lists and Tuples - US Population Data In this assignment, you will be reading the contents of a file into a list. This file contains the midyear population of the United States, in thousands, during the years 1950 through 1990. The first line in the file contains the population for 1950, the second line contains the populations for 1951, and so forth. You will ask the user to input a specific year to check the population...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT