| |
| """eda.363 |
| |
| Automatically generated by Colab. |
| |
| Original file is located at |
| https://colab.research.google.com/drive/1LWUvpKSaZSgOHW-h4GzL9_0NM3RRIxTx |
| """ |
|
|
| import numpy as np |
| import pandas as pd |
| import matplotlib.pyplot as plt |
| import seaborn as sns |
|
|
| df = pd.read_csv("/content/World-happiness-report-updated_2024.csv", encoding='latin-1') |
| df.head(5) |
|
|
| df.describe() |
|
|
| df.info() |
|
|
| df.isnull().sum() |
|
|
| numeric_cols = df.select_dtypes(include=np.number).columns |
| df[numeric_cols] = df[numeric_cols].fillna(df[numeric_cols].mean()) |
|
|
| df2024 = pd.read_csv("/content/World-happiness-report-2024.csv", encoding='latin-1') |
| df2024.head(5) |
|
|
| df2024.describe() |
|
|
| df2024.info() |
|
|
| df2024.isnull().sum() |
|
|
| numeric_cols = df2024.select_dtypes(include=np.number).columns |
| df2024[numeric_cols] = df2024[numeric_cols].fillna(df2024[numeric_cols].mean()) |
|
|
| df2024['Country name'].unique() |
|
|
| sns.countplot(x = 'Regional indicator', data = df2024) |
| plt.xticks(rotation = 60) |
| plt.show() |
|
|
| list_features = ['Social support', 'Freedom to make life choices', 'Generosity', 'Perceptions of corruption'] |
| sns.boxplot(data=df2024.loc[:,list_features],orient='h',palette = 'Set3') |
| plt.show() |
|
|
| list_features = ['Ladder score', 'Log GDP per capita'] |
| sns.boxplot(data=df2024.loc[:,list_features],orient='h',palette = 'Set3') |
| plt.show() |
|
|
| df2024_happiest_unhappiest = df2024[(df2024.loc[:,'Ladder score']>7.4) | (df2024.loc[:,'Ladder score']<3.5)] |
| sns.barplot(x = 'Ladder score', y= 'Country name', data = df2024_happiest_unhappiest, palette = 'coolwarm') |
| plt.title('Happiest and Unhappiest Countries in 2024') |
| plt.show() |
|
|
| plt.figure(figsize=(15,8)) |
| sns.kdeplot(x=df2024['Ladder score'], hue = df2024['Regional indicator'], fill = True, linewidth = 2) |
| plt.axvline(df2024['Ladder score'].mean(),c= 'black') |
| plt.title('Ladder Score Distribution by Regional Indicator') |
| plt.show() |
|
|
| import plotly.express as px |
| fig = px.choropleth(df.sort_values('year'), |
| locations='Country name', |
| color='Life Ladder', |
| locationmode = 'country names', |
| animation_frame = 'year') |
| fig.update_layout(title = 'Life Ladder Comparison by Countires') |
|
|
| df2024_generosity = df2024[(df2024.loc[:,'Generosity']>0.6)|(df2024.loc[:,'Generosity']<0.05)] |
| sns.barplot(x = 'Generosity', y = 'Country name', data = df2024_generosity, palette= 'coolwarm') |
| plt.title('Most Generous and Most Ungenerous Countries in 2024') |
| plt.show() |
|
|
| fig = px.choropleth(df.sort_values('year'), |
| locations = 'Country name', |
| color = 'Generosity', |
| locationmode = 'country names', |
| animation_frame = 'year') |
| fig.update_layout(title = 'Generosity Comparison by Countries') |
| fig.show() |
|
|
| sns.swarmplot(x = "Regional indicator", y = "Generosity", data = df2024, palette="Set1") |
| plt.xticks(rotation = 90) |
| plt.title("Generous Distribution by Regional Indicator in 2021") |
| plt.show() |
|
|
| non_numeric_columns = df.select_dtypes(exclude=['float64', 'int64']).columns |
| df_numeric = df.drop(columns=non_numeric_columns) |
| correlation_matrix = df_numeric.corr() |
| sns.heatmap(correlation_matrix, annot = True, fmt ='.2f', linewidth = .7) |
| plt.title('Relationship Between Features') |
| plt.show() |
|
|
| sns.clustermap(correlation_matrix, center = 0, cmap = 'vlag', dendrogram_ratio = (0.1,0.2), annot = True, linewidth = .7, figsize=(10,10)) |
| plt.show() |