Skip to content

Commit 3b65128

Browse files
committed
review from html
1 parent 7a9dbf6 commit 3b65128

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

lectures/inequality.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,6 @@ Let's examine the Gini coefficient in some simulations.
420420
First the code below enables us to compute the Gini coefficient.
421421

422422
```{code-cell} ipython3
423-
:tags: [hide-input]
424423
425424
def gini_coefficient(y):
426425
r"""
@@ -529,14 +528,15 @@ Let us fetch the data for the USA and request for it to be returned as a `DataFr
529528
```{code-cell} ipython3
530529
data = wb.data.DataFrame("SI.POV.GINI", "USA")
531530
data.head(n=5)
532-
data.columns = data.columns.map(lambda x: int(x.replace('YR',''))) # remove 'YR' in index and convert to int
531+
# remove 'YR' in index and convert to integer
532+
data.columns = data.columns.map(lambda x: int(x.replace('YR','')))
533533
```
534534

535535
**Note:** This package often returns data with year information contained in the columns. This is not always convenient for simple plotting with pandas so it can be useful to transpose the results before plotting
536536

537537
```{code-cell} ipython3
538-
data = data.T # transpose to get data series as columns and years as rows
539-
data_usa = data['USA'] # obtain a simple series of USA data
538+
data = data.T # Obtain years as rows
539+
data_usa = data['USA'] # Series of US data
540540
```
541541

542542
The `data_usa` series can now be plotted using the pandas `.plot` method.
@@ -575,7 +575,8 @@ mystnb:
575575
---
576576
# Fetch gini data for all countries
577577
gini_all = wb.data.DataFrame("SI.POV.GINI")
578-
gini_all.columns = gini_all.columns.map(lambda x: int(x.replace('YR',''))) # remove 'YR' in index and convert to int
578+
# remove 'YR' in index and convert to integer
579+
gini_all.columns = gini_all.columns.map(lambda x: int(x.replace('YR','')))
579580
580581
# Create a long series with a multi-index of the data to get global min and max values
581582
gini_all = gini_all.unstack(level='economy').dropna()
@@ -743,7 +744,7 @@ As we saw earlier in this lecture we used `wbgapi` to get Gini data across many
743744
In this section we will compare a few western economies and look at the evolution in their respective Gini coefficients
744745

745746
```{code-cell} ipython3
746-
data = gini_all.unstack() # Obtain data for all countries as a table
747+
data = gini_all.unstack()
747748
data.columns
748749
```
749750

@@ -803,7 +804,8 @@ Let's take another look at the USA, Norway, and the United Kingdom.
803804
```{code-cell} ipython3
804805
countries = ['USA', 'NOR', 'GBR']
805806
gdppc = wb.data.DataFrame("NY.GDP.PCAP.KD", countries)
806-
gdppc.columns = gdppc.columns.map(lambda x: int(x.replace('YR',''))) # remove 'YR' in index and convert to int
807+
# remove 'YR' in index and convert to integer
808+
gdppc.columns = gdppc.columns.map(lambda x: int(x.replace('YR','')))
807809
gdppc = gdppc.T
808810
```
809811

@@ -837,19 +839,14 @@ max_year = plot_data.year.max()
837839
improve clarity in the chart including the different end years associated with each countries time series.
838840

839841
```{code-cell} ipython3
840-
labels = [1979, 1986, 1991, 1995, 2000, 2020, 2021, 2022] + list(range(min_year,max_year,5))
842+
labels = [1979, 1986, 1991, 1995, 2000, 2020, 2021, 2022] /
843+
+ list(range(min_year,max_year,5))
841844
plot_data.year = plot_data.year.map(lambda x: x if x in labels else None)
842845
```
843846

844847
(fig:plotly-gini-gdppc-years)=
845848

846849
```{code-cell} ipython3
847-
---
848-
mystnb:
849-
figure:
850-
caption: Gini coefficients and GDP per capita (USA, United Kingdom, and Norway)
851-
name: gini_gdppc_usa_gbr_nor1
852-
---
853850
fig = px.line(plot_data,
854851
x = "gini",
855852
y = "gdppc",

0 commit comments

Comments
 (0)