#importing the libraries import pandas as pd import numpy as np import seaborn as sns import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D
import warnings warnings.filterwarnings('ignore')
dataset列
Country name:国家名字
Regional indicator:地区
Ladder score:幸福指数
Standard error of ladder score :幸福指数标准差
upperwhisker : 标准差上界
lowerwhisker:标准差下界
Logged GDP per capita:人均GDP
Social support:社会保障?
Healthy life expectancy:人均寿命
Freedom to make life choices:做出人生决定的自由度?
Generosity:慷慨?
Perceptions of corruption:腐败程度
Ladder score in Dystopia
Explained by: Log GDP per capita
Explained by: Social support
Explained by: Healthy life expectancy
Explained by: Freedom to make life choices
Explained by: Generosity
Explained by: Perceptions of corruption
Dystopia + residual
A
B
社会保障
人均寿命
人均GDP
幸福指数
慷慨指数
做出人生决定的自由度
地区
1 2 3
#load the dataset df = pd.read_csv('world-happiness-report-2021.csv') df.head().transpose()
0
1
2
3
4
Country name
Finland
Denmark
Switzerland
Iceland
Netherlands
Regional indicator
Western Europe
Western Europe
Western Europe
Western Europe
Western Europe
Ladder score
7.842
7.62
7.571
7.554
7.464
Standard error of ladder score
0.032
0.035
0.036
0.059
0.027
upperwhisker
7.904
7.687
7.643
7.67
7.518
lowerwhisker
7.78
7.552
7.5
7.438
7.41
Logged GDP per capita
10.775
10.933
11.117
10.878
10.932
Social support
0.954
0.954
0.942
0.983
0.942
Healthy life expectancy
72.0
72.7
74.4
73.0
72.4
Freedom to make life choices
0.949
0.946
0.919
0.955
0.913
Generosity
-0.098
0.03
0.025
0.16
0.175
Perceptions of corruption
0.186
0.179
0.292
0.673
0.338
Ladder score in Dystopia
2.43
2.43
2.43
2.43
2.43
Explained by: Log GDP per capita
1.446
1.502
1.566
1.482
1.501
Explained by: Social support
1.106
1.108
1.079
1.172
1.079
Explained by: Healthy life expectancy
0.741
0.763
0.816
0.772
0.753
Explained by: Freedom to make life choices
0.691
0.686
0.653
0.698
0.647
Explained by: Generosity
0.124
0.208
0.204
0.293
0.302
Explained by: Perceptions of corruption
0.481
0.485
0.413
0.17
0.384
Dystopia + residual
3.253
2.868
2.839
2.967
2.798
1
# df[["Country name", "Freedom to make life choices"]].sort_values(by="Freedom to make life choices", ascending=False).values