<jupyter_start><jupyter_text>Top and bottom countries in Swedish mediaIn this notebook, we look at how the media coverage of the United States compares to the least covered countries in the world, in Swedish media.- Sources: Datastory, Mynewsflash, Natural Earth Data- Date: 2019-05-10  Setup<jupyter_code>import pandas as pd
import geopandas as gpd
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap

%config InlineBackend.figure_format = 'retina'

plt.style.use('../assets/datastory.mpltstyle')
# Load snapshot of the news index data
df = pd.read_csv('../data/raw/2019-05-10-media-top-bottom.csv')
df.head()
# Natural Earth Data shapefile
geo = gpd.read_file('../data/geo/ne_110m_admin_0_sovereignty/ne_110m_admin_0_sovereignty.shp')

# Reproject to Sphere Robinson
geo = geo.to_crs('+proj=robin +lon_0=0 +x_0=0 +y_0=0 +a=6371000 +b=6371000 +units=m no_defs')

# Remove some units
geo = geo[~geo['ADMIN'].isin(['Antarctica', 'Sweden'])]
geo.head(2)<jupyter_output><empty_output><jupyter_text>Calculate `n` countries comparable to USA<jupyter_code>df = df.sort_values('no_articles')
df['cumsum'] = df.no_articles.cumsum()

# Is the cumulative sum below the sum for USA?
df['below_usa'] = df['cumsum'] < \
    df[df.iso_a3 == 'USA'].no_articles.iloc[0]

# Assign categorical values
df['cat'] = df.apply(lambda x: 'x' if x.below_usa \
                     else 'y' if x.iso_a3 == 'USA' \
                     else 'z', axis=1)<jupyter_output><empty_output><jupyter_text>Merge data<jupyter_code>geo = geo.merge(df, left_on='ADM0_A3_IS', right_on='iso_a3', how='left')

# A few countries in the shapefile
# are missing in the country counts
geo['cat'] = geo.cat.fillna('z')<jupyter_output><empty_output><jupyter_text>Plot<jupyter_code># Custom cmap
cmap = LinearSegmentedColormap.from_list('dcmap', [
    (0, '#ff713f'),
    (.5, '#57d298'),
    (1, '#d6d6d7')])
ax = geo.plot(column='cat', cmap=cmap, figsize=(20, 15));
ax.spines['left'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.set_xticks([])
ax.set_yticks([])
ax.set_xlim(left=-1.35e7, right=1.67e7);

plt.gcf().savefig('../charts/2019-05-10-media-top-bottom.png')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15530136383633963, 'fraction_numerical': 0.03783545974483062, 'mean_word_length': 5.405633802816902, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '13320', 'license': 'MIT', 'n_tokens_mistral': 939, 'n_tokens_neox': 859, 'n_words': 177, 'path': 'notebooks/2019-05-10-media-top-bottom.ipynb', 'repo_name': 'datastory-org/weekly-chart', 'size': '2273'}