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%...
What does Uk < Us mean?
What does Uk < Us mean?
"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.
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...
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...
(1 point) Our decisions depend on how the options are presented to us. Here's an experiment...
(1 point) Our decisions depend on how the options are presented to us. Here's an experiment that illustrates this phenomenon. Tell 20 subjects that they have been given $50 but can't keep it all. Then present them with a long series of choices between bets they can make with the $50. Scattered among these choices in random order are 64 choices between a fixed amount and an all-or-nothing gamble. The odds for the gamble are always the same, but 32...
What is the differences between UK and US balance sheet?
What is the differences between UK and US balance sheet?
Wells describes the full-blown creation of "car country" in the interwar years (1919 - 1941). Here's...
Wells describes the full-blown creation of "car country" in the interwar years (1919 - 1941). Here's the question: On the whole, did the creation of "car country" make Americans better off than they were before? Why or why not? please post a response to the following question. Your response should be around 200-300 words in length and should include specific, cited evidence from this assignment in Christopher Well, Car Country (Chapters 4-6).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT