From b318cb2d0a559ff8fd75b4db849cfc15724feea0 Mon Sep 17 00:00:00 2001 From: mmcky Date: Fri, 28 Mar 2025 11:04:47 +1100 Subject: [PATCH 1/5] FIX: FutureWarning in heavy_tails --- lectures/heavy_tails.md | 46 ++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/lectures/heavy_tails.md b/lectures/heavy_tails.md index 15f2970e..c1b88416 100644 --- a/lectures/heavy_tails.md +++ b/lectures/heavy_tails.md @@ -4,7 +4,7 @@ jupytext: extension: .md format_name: myst format_version: 0.13 - jupytext_version: 1.16.1 + jupytext_version: 1.16.7 kernelspec: display_name: Python 3 (ipykernel) language: python @@ -31,7 +31,7 @@ import yfinance as yf import pandas as pd import statsmodels.api as sm -from pandas_datareader import wb +import wbgapi as wb from scipy.stats import norm, cauchy from pandas.plotting import register_matplotlib_converters register_matplotlib_converters() @@ -790,24 +790,24 @@ def empirical_ccdf(data, :tags: [hide-input] def extract_wb(varlist=['NY.GDP.MKTP.CD'], - c='all_countries', + c='all', s=1900, e=2021, varnames=None): - if c == "all_countries": - # Keep countries only (no aggregated regions) - countries = wb.get_countries() - countries_name = countries[countries['region'] != 'Aggregates']['name'].values - c = "all" - df = wb.download(indicator=varlist, country=c, start=s, end=e).stack().unstack(0).reset_index() - df = df.drop(['level_1'], axis=1).transpose() + df = wb.data.DataFrame(varlist, economy=c, time=range(s, e+1, 1), skipAggs=True) + df.index.name = 'country' + if varnames is not None: - df.columns = varnames - df = df[1:] + df.columns = variable_names + + df.index = df.index.map(lambda x: cntry_mapper[x]) #map iso3c to name values - df1 =df[df.index.isin(countries_name)] - return df1 + return df +``` + +```{code-cell} ipython3 +df_gdp1 ``` ### Firm size @@ -914,13 +914,25 @@ variable_code = ['NY.GDP.MKTP.CD', 'NY.GDP.PCAP.CD'] variable_names = ['GDP', 'GDP per capita'] df_gdp1 = extract_wb(varlist=variable_code, - c="all_countries", - s="2021", - e="2021", + c="all", + s=2021, + e=2021, varnames=variable_names) df_gdp1.dropna(inplace=True) ``` +```{code-cell} ipython3 + +``` + +```{code-cell} ipython3 + +``` + +```{code-cell} ipython3 + +``` + ```{code-cell} ipython3 --- mystnb: From 5807435f6bf4870936c259750b5cd55339d754c6 Mon Sep 17 00:00:00 2001 From: Matt McKay Date: Fri, 28 Mar 2025 11:06:04 +1100 Subject: [PATCH 2/5] Update lectures/heavy_tails.md --- lectures/heavy_tails.md | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/lectures/heavy_tails.md b/lectures/heavy_tails.md index c1b88416..ed41ede8 100644 --- a/lectures/heavy_tails.md +++ b/lectures/heavy_tails.md @@ -921,18 +921,6 @@ df_gdp1 = extract_wb(varlist=variable_code, df_gdp1.dropna(inplace=True) ``` -```{code-cell} ipython3 - -``` - -```{code-cell} ipython3 - -``` - -```{code-cell} ipython3 - -``` - ```{code-cell} ipython3 --- mystnb: From 7f70a05b137409a5f9811f8daf976cf1dcb96226 Mon Sep 17 00:00:00 2001 From: mmcky Date: Fri, 28 Mar 2025 11:07:52 +1100 Subject: [PATCH 3/5] minor typo --- lectures/heavy_tails.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lectures/heavy_tails.md b/lectures/heavy_tails.md index ed41ede8..2ca95d8d 100644 --- a/lectures/heavy_tails.md +++ b/lectures/heavy_tails.md @@ -806,10 +806,6 @@ def extract_wb(varlist=['NY.GDP.MKTP.CD'], return df ``` -```{code-cell} ipython3 -df_gdp1 -``` - ### Firm size Here is a plot of the firm size distribution for the largest 500 firms in 2020 taken from Forbes Global 2000. From 7758078770a7704006a21b2f43e40a232e9730b5 Mon Sep 17 00:00:00 2001 From: mmcky Date: Fri, 28 Mar 2025 11:31:02 +1100 Subject: [PATCH 4/5] fix install of wbgapi --- lectures/heavy_tails.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lectures/heavy_tails.md b/lectures/heavy_tails.md index 2ca95d8d..5441b7b2 100644 --- a/lectures/heavy_tails.md +++ b/lectures/heavy_tails.md @@ -19,7 +19,7 @@ In addition to what's in Anaconda, this lecture will need the following librarie ```{code-cell} ipython3 :tags: [hide-output] -!pip install --upgrade yfinance pandas_datareader +!pip install --upgrade yfinance wbgapi ``` We use the following imports. From 75a0cd47b649622be8d0a7bb2b4439917456a6fa Mon Sep 17 00:00:00 2001 From: mmcky Date: Fri, 28 Mar 2025 12:17:45 +1100 Subject: [PATCH 5/5] fix cntry_mapper --- lectures/heavy_tails.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lectures/heavy_tails.md b/lectures/heavy_tails.md index 5441b7b2..6a27df31 100644 --- a/lectures/heavy_tails.md +++ b/lectures/heavy_tails.md @@ -800,7 +800,8 @@ def extract_wb(varlist=['NY.GDP.MKTP.CD'], if varnames is not None: df.columns = variable_names - + + cntry_mapper = pd.DataFrame(wb.economy.info().items)[['id','value']].set_index('id').to_dict()['value'] df.index = df.index.map(lambda x: cntry_mapper[x]) #map iso3c to name values return df