Question: import pandas as pd import seaborn as sns import matplotlib.pyplot as plt % matplotlib inline pd . options.display.float _ format = ' { : .

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
pd.options.display.float_format ='{:.2f}'.format
def produce_summary_table(dfraw = pd.read_excel('WHR2018Chapter2OnlineData.xls', sheet_name='Table2.1')
):
cols_to_include =['country', 'year', 'Life Ladder',
'Positive affect','Negative affect',
'Log GDP per capita', 'Social support',
'Healthy life expectancy at birth',
'Freedom to make life choices',
'Generosity', 'Perceptions of corruption']
df = dfraw[cols_to_include]
column_renaming ={'count': 'N', 'mean': 'Mean', 'std': 'Std. Dev.', 'min': 'Min.', 'max': 'Max.'}
column_order =['Mean','Std. Dev.', 'Min.', 'Max.','N']
df_transposed2= df.describe().T
df_transposed2
df_transposed2= df_transposed2.drop('year')
df_transposed2
df_dropped2= df_transposed2.drop(['25%','50%','75%'], axis=1)
df_dropped2
df_renamed2= df_dropped2.rename(columns=column_renaming)
dfsummary2= df_renamed2
dfsummary2['N']= dfsummary2['N'].astype(int)
return dfsummary2
df_summary_new = produce_summary_table()
df = df_summary_new[column_order]
df
In the empty code cell below, do the following:
Create three new dataframes for each of the year ranges associated with Tables 5,6, and 7, by extracting the appropriate set of years. Using the function you wrote above, create a summary table for each dataframe (your function takes a dataframe as input). Assign the resulting summary tables to the names dfsummary0507, dfsummary0810, and dfsummary1517.
The remaining three code cells below are populated with the table names dfsummary0507, dfsummary0810, and dfsummary1517. Once you have created these summary tables as outlined above, execute these cells to compare your tables with the corresponding tables in WHR Appendix 1.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!