You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
13 lines
716 B
Python
13 lines
716 B
Python
1 year ago
|
import pandas as pd
|
||
|
|
||
|
def prepare_country_stats(oecd_bli, gdp_per_capita):
|
||
|
oecd_bli = oecd_bli[oecd_bli["INEQUALITY"]=="TOT"]
|
||
|
oecd_bli = oecd_bli.pivot(index="Country", columns="Indicator", values="Value")
|
||
|
gdp_per_capita.rename(columns={"2015": "GDP per capita"}, inplace=True)
|
||
|
gdp_per_capita.set_index("Country", inplace=True)
|
||
|
full_country_stats = pd.merge(left=oecd_bli, right=gdp_per_capita,left_index=True, right_index=True)
|
||
|
full_country_stats.sort_values(by="GDP per capita", inplace=True)
|
||
|
remove_indices = [0, 1, 6, 8, 33, 34, 35]
|
||
|
keep_indices = list(set(range(36)) - set(remove_indices))
|
||
|
return full_country_stats[["GDP per capita", 'Life satisfaction']].iloc[keep_indices]
|