The demonstration markdown file [World Population](./World Population.md) is copied from Jupytext.
Last active
December 17, 2021 19:15
-
-
Save fcollonval/527631f0193f8c4f801d68e1b90a5ba2 to your computer and use it in GitHub Desktop.
Jupytext in French
This file contains 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
{ | |
"@jupyterlab/translation-extension:plugin": {"locale": "fr_FR"}, | |
"@jupyterlab/docmanager-extension:plugin": { | |
"defaultViewers": { | |
"markdown": "Jupytext Notebook", | |
"myst": "Jupytext Notebook", | |
"r-markdown": "Jupytext Notebook", | |
"quarto": "Jupytext Notebook" | |
} | |
} | |
} |
This file contains 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
#!/usr/bin/env bash | |
set -eux | |
mkdir -p ${NB_PYTHON_PREFIX}/share/jupyter/lab/settings | |
cp overrides.json ${NB_PYTHON_PREFIX}/share/jupyter/lab/settings |
This file contains 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
jupyterlab>=3.2.0,<4.0.0 | |
jupytext >= 1.13.0,<2.0.0 | |
jupyterlab-language-pack-fr-FR | |
plotly | |
matplotlib | |
wordcloud | |
pandas | |
wbdata | |
bash_kernel |
jupyter | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
In the below we retrieve population data from the World Bank using the wbdata python package
import pandas as pd
import wbdata as wb
pd.options.display.max_rows = 6
pd.options.display.max_columns = 20
Corresponding indicator is found using search method - or, directly, the World Bank site.
wb.search_indicators('Population, total') # SP.POP.TOTL
# wb.search_indicators('area')
# => https://data.worldbank.org/indicator is easier to use
Now we download the population data
indicators = {'SP.POP.TOTL': 'Population, total',
'AG.SRF.TOTL.K2': 'Surface area (sq. km)',
'AG.LND.TOTL.K2': 'Land area (sq. km)',
'AG.LND.ARBL.ZS': 'Arable land (% of land area)'}
data = wb.get_dataframe(indicators, convert_date=True).sort_index()
data
World is one of the countries
data.loc['World']
Can we classify over continents?
data.loc[(slice(None), '2017-01-01'), :]['Population, total'].dropna(
).sort_values().tail(60).index.get_level_values('country')
Extract zones manually (in order of increasing population)
zones = ['North America', 'Middle East & North Africa',
'Latin America & Caribbean', 'Europe & Central Asia',
'Sub-Saharan Africa', 'South Asia',
'East Asia & Pacific'][::-1]
And extract population information (and check total is right)
population = data.loc[zones]['Population, total'].swaplevel().unstack()
population = population[zones]
assert all(data.loc['World']['Population, total'] == population.sum(axis=1))
import matplotlib.pyplot as plt
plt.clf()
plt.figure(figsize=(10, 5), dpi=100)
plt.stackplot(population.index, population.values.T / 1e9)
plt.legend(population.columns, loc='upper left')
plt.ylabel('Population count (B)')
plt.show()
import plotly.offline as offline
import plotly.graph_objs as go
offline.init_notebook_mode()
data = [go.Scatter(x=population.index, y=population[zone], name=zone, stackgroup='World')
for zone in zones]
fig = go.Figure(data=data,
layout=go.Layout(title='World population'))
offline.iplot(fig)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment