1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
Age21_W = df21.loc[:,['Q3','Q1', 'year']].reset_index().rename(columns={'Q3':'East_Asia', 'Q1':'age'}).fillna('etc') Age20_W = df20.loc[:,['Q3','Q1','year']].reset_index().rename(columns={'Q3':'East_Asia', 'Q1':'age'}).fillna('etc') Age19_W = df19.loc[:,['Q3','Q1','year']].reset_index().rename(columns={'Q3':'East_Asia', 'Q1':'age'}).fillna('etc') Age18_W = df18.loc[:,['Q3','Q2','year']].reset_index().rename(columns={'Q3':'East_Asia', 'Q2':'age'}).fillna('etc')
Age5y_W= pd.concat([Age21_W, Age20_W, Age19_W, Age18_W]) Age5y_W= (Age5y_W.replace(['60-69', '70+', '70-79', '80+'], '60+') .replace(['22-24', '25-29'], '22-29') .replace(['30-34', '35-39'], '30-39') .replace(['40-44', '45-49'], '40-49') .replace(['50-54', '55-59'], '50-59') .groupby(['year', 'age']) .size() .reset_index() .rename(columns = {0:"Count"}))
Age21_percent_W = Age5y_W[Age5y_W['year'] == "2021"].reset_index(drop = True) Age21_percent_W['percentage'] = Age21_percent_W["Count"] / Age21_percent_W["Count"].sum() Age21_percent_W['%'] = np.round(Age21_percent_W['percentage'] * 100, 1)
Age20_percent_W = Age5y_W[Age5y_W['year'] == "2020"].reset_index(drop = True) Age20_percent_W['percentage'] = Age20_percent_W["Count"] / Age20_percent_W["Count"].sum() Age20_percent_W['%'] = np.round(Age20_percent_W['percentage'] * 100, 1)
Age19_percent_W = Age5y_W[Age5y_W['year'] == "2019"].reset_index(drop = True) Age19_percent_W['percentage'] = Age19_percent_W["Count"] / Age19_percent_W["Count"].sum() Age19_percent_W['%'] = np.round(Age19_percent_W['percentage'] * 100, 1)
Age18_percent_W = Age5y_W[Age5y_W['year'] == "2018"].reset_index(drop = True) Age18_percent_W['percentage'] = Age18_percent_W["Count"] / Age18_percent_W["Count"].sum() Age18_percent_W['%'] = np.round(Age18_percent_W['percentage'] * 100, 1)
Age5y_percent_W = pd.concat([Age18_percent_W, Age19_percent_W, Age20_percent_W, Age21_percent_W], ignore_index = True) Age5y_percent_W= pd.pivot(Age5y_percent_W, index = "year", columns = 'age', values = "%").reset_index() Age5y_percent_W
Age21 = df21_Ea.loc[:,['Q3','Q1', 'year']].reset_index().rename(columns={'Q3':'East_Asia', 'Q1':'age'}).fillna('etc') Age20 = df20_Ea.loc[:,['Q3','Q1','year']].reset_index().rename(columns={'Q3':'East_Asia', 'Q1':'age'}).fillna('etc') Age19 = df19_Ea.loc[:,['Q3','Q1','year']].reset_index().rename(columns={'Q3':'East_Asia', 'Q1':'age'}).fillna('etc') Age18 = df18_Ea.loc[:,['Q3','Q2','year']].reset_index().rename(columns={'Q3':'East_Asia', 'Q2':'age'}).fillna('etc')
Age5y= pd.concat([Age21, Age20, Age19, Age18]) Age5y= (Age5y.replace(['60-69', '70+', '70-79', '80+'], '60+') .replace(['22-24', '25-29'], '22-29') .replace(['30-34', '35-39'], '30-39') .replace(['40-44', '45-49'], '40-49') .replace(['50-54', '55-59'], '50-59') .groupby(['year', 'age']) .size() .reset_index() .rename(columns = {0:"Count"}))
Age21_percent = Age5y[Age5y['year'] == "2021"].reset_index(drop = True) Age21_percent['percentage'] = Age21_percent["Count"] / Age21_percent["Count"].sum() Age21_percent['%'] = np.round(Age21_percent['percentage'] * 100, 1) Age21_percent
Age20_percent = Age5y[Age5y['year'] == "2020"].reset_index(drop = True) Age20_percent['percentage'] = Age20_percent["Count"] / Age20_percent["Count"].sum() Age20_percent['%'] = np.round(Age20_percent['percentage'] * 100, 1) Age20_percent
Age19_percent = Age5y[Age5y['year'] == "2019"].reset_index(drop = True) Age19_percent['percentage'] = Age19_percent["Count"] / Age19_percent["Count"].sum() Age19_percent['%'] = np.round(Age19_percent['percentage'] * 100, 1) Age19_percent
Age18_percent = Age5y[Age5y['year'] == "2018"].reset_index(drop = True) Age18_percent['percentage'] = Age18_percent["Count"] / Age18_percent["Count"].sum() Age18_percent['%'] = np.round(Age18_percent['percentage'] * 100, 1) Age18_percent
Age5y_percent = pd.concat([Age18_percent, Age19_percent, Age20_percent, Age21_percent], ignore_index = True) Age5y_percent= pd.pivot(Age5y_percent, index = "year", columns = 'age', values = "%").reset_index() Age5y_percent
|