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
| from datetime import datetime | |
| date_format = '%Y-%m-%dT%H:%M:%S' | |
| currency['Date'] = currency['DateTime'].apply(lambda x: datetime.strptime(x, date_format)) | |
| inflation['Date'] = inflation['DateTime'].apply(lambda x: datetime.strptime(x, date_format)) | |
| prices['Date'] = prices['DATE'].apply(lambda x: datetime.strptime(x, '%m/%d/%y')) |
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 pandas as pd | |
| parent_url = 'https://raw.githubusercontent.com/numbers-coffee/blog/master/real_prices/' | |
| currency = pd.read_csv(parent_url + 'currency.csv') | |
| inflation = pd.read_csv(parent_url + 'inflation.csv') | |
| prices = pd.read_csv(parent_url + 'prices.csv') |
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 |
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
| 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
| 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
| 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
| 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_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
| import geopandas | |
| world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres')) | |
| world.plot() |