This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def cagr(series): | |
| start_val = series.iloc[0] | |
| end_val = series.iloc[-1] | |
| num_vals = len(series) | |
| CAGR = (end_val/start_val)**(1/num_vals)-1 | |
| prefix = '' | |
| if CAGR > 0: | |
| prefix = '+' | |
| return prefix + '{:.1%}'.format(CAGR) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| labels = [] | |
| y_vals = [] | |
| cum_sum = 0 | |
| for col_num, country_name in enumerate(production_table.columns): | |
| label = country_name + " " + cagr(production_table[country_name]) | |
| labels.append(label) | |
| prod_val = production_table.iloc[-1,col_num] | |
| y_vals.append((cum_sum * 2 + prod_val)/2) | |
| cum_sum += prod_val |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import geopandas | |
| world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres')) | |
| world.plot() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| world_map = world[world.name != 'Antarctica'] | |
| world_map = world_map[['name', 'geometry']] | |
| world_map.set_index('name', inplace=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fig, ax = plt.subplots(figsize=(20,8)) | |
| ax.set_aspect('equal') | |
| world_map.plot(color='#f2f2f2', edgecolor="Grey", ax=ax) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| world_production = attribute_query('Production') | |
| world_production.fillna(0,inplace=True) | |
| world_production = world_production.iloc[:,-YEARS_IN_SERIES:] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| world_production.rename({ | |
| "Cote d'Ivoire": "Côte d'Ivoire", | |
| "Central African Republic": "Central African Rep.", | |
| "Congo (Kinshasa)": "Dem. Rep. Congo", | |
| "Dominican Republic": "Dominican Rep.", | |
| "Laos": "Lao PDR" | |
| }, inplace=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def cagr(series): | |
| start_val = series.iloc[0] | |
| if not start_val: | |
| return None | |
| end_val = series.iloc[-1] | |
| num_vals = len(series) | |
| CAGR = (end_val/start_val)**(1/num_vals)-1 | |
| return CAGR | |
| world_production['CAGR'] = world_production.apply(cagr, axis=1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cagr_map = pd.concat([world_map, world_production], axis=1, sort=True) | |
| cagr_map.fillna(0, inplace=True) | |
| cagr_map.plot(column='CAGR', cmap='Blues') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| growing_map = cagr_map[cagr_map.CAGR > 0] | |
| growing_map.plot(column='CAGR', cmap='YlGn', scheme='fisher_jenks', edgecolor='black', ax=ax) | |
| shrinking_map = cagr_map[cagr_map.CAGR < 0] | |
| shrinking_map.plot(column='CAGR', cmap='Reds_r', scheme='fisher_jenks', edgecolor='black', ax=ax) | |
| ax.set_ylim([-23.5,23.5]) | |
| ax.set_xlim([-120,160]) | |
| fig |