Skip to content

Latest commit

 

History

History
2343 lines (1429 loc) · 44.8 KB

notebook.md

File metadata and controls

2343 lines (1429 loc) · 44.8 KB

Table of contents

import json
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import datetime

import seaborn
seaborn.set_theme()

pd.set_option('future.no_silent_downcasting', True)
with open('regions-m49.json') as f:
    regions = json.load(f)['regions']
    regions = {v: n for n, v in regions.items()}

with open('countries-m49.json') as f:
    countries = json.load(f)['countries']
    country_subregions = {c['name']: regions[c['subRegion']] for c in countries}
    country_regions = {c['name']: regions[c['region']] for c in countries}
country_mapping = {
    'Czech Republic': 'Czechia',
    'Iran': 'Iran (Islamic Republic of)',
    'Russia': 'Russian Federation',
    'South Korea': 'Republic of Korea',
    'Taiwan': 'China',  # UN is an abomination
    'Turkey': 'T\u00fcrkiye',
    'United Kingdom': 'United Kingdom of Great Britain and Northern Ireland',
    'United States': 'United States of America',
}

max_year = 2023
years = range(1954, max_year + 1)
max_date = pd.to_datetime(datetime.date(year = max_year + 1, month = 1, day = 1))

copyright_text = 'CC BY-SA 4.0 Andrey Upadyshev (image) and\nWikipedia, List of commercial nuclear reactors (data)'
copyright_font_size = 10

def format_years_ticks(ax):
    for label in ax.get_xticklabels():
        if label.get_text() in ('1957', '1979', '1986', '2011'):
            label.set_color('red')


def format_number_plants_ticks(ax, ymin, ymax):
    def fmt(val, pos):
        return int(abs(val))
    ax.yaxis.set_major_formatter(fmt)
    ax.set_ylim(-ymin, ymax)
orig_input_df = pd.read_csv('./reactors.csv').convert_dtypes()
for col in ('Begin building', 'Commercial operation', 'Closed'):
    orig_input_df[f'{col} date'] = pd.to_datetime(orig_input_df[col])
    orig_input_df[f'{col}'] = orig_input_df[f'{col} date'].dt.year
input_df = orig_input_df[orig_input_df['Begin building'].notna() & (orig_input_df['Begin building'] <= max_year)].reset_index(drop=True)
input_df.loc[input_df['Commercial operation'] > max_year, 'Commercial operation'] = None
input_df.loc[input_df['Closed'] > max_year, 'Closed'] = None

input_df['SubRegion'] = input_df['Country'].map(lambda x: country_subregions[country_mapping.get(x, x)])
input_df['Region'] = input_df['Country'].map(lambda x: country_regions[country_mapping.get(x, x)])
input_df['Operated closed'] = input_df['Closed'].where(input_df['Commercial operation'].notna(), None)
input_df['Construction time'] = (input_df['Commercial operation date'] - input_df['Begin building date']).dt.total_seconds() / (365.25 * 24 * 60 * 60)
input_df
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; }
.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}
</style>
Country Plant name Unit No. Type Model Status Capacity (MW) Begin building Commercial operation Closed Begin building date Commercial operation date Closed date SubRegion Region Operated closed Construction time
0 Argentina Atucha 1 PHWR Siemens-KWU Operational 335.0 1968.0 1974.0 NaN 1968-06-01 1974-06-24 NaT Latin America and the Caribbean Americas NaN 6.061602
1 Argentina Atucha 2 PHWR Siemens-KWU Operational 692.0 1981.0 2014.0 NaN 1981-07-14 2014-06-27 NaT Latin America and the Caribbean Americas NaN 32.952772
2 Argentina Embalse 1 PHWR CANDU-6 Operational 600.0 1974.0 1984.0 NaN 1974-04-01 1984-01-20 NaT Latin America and the Caribbean Americas NaN 9.804244
3 Argentina CAREM 1 PWR CAREM25 Under construction 25.0 2014.0 NaN NaN 2014-02-08 NaT NaT Latin America and the Caribbean Americas NaN NaN
4 Armenia Metsamor 1 PWR VVER-440/V-270 Shut down 376.0 1969.0 1977.0 1989.0 1969-07-01 1977-10-06 1989-02-25 Western Asia Asia 1989.0 8.265572
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
746 United States Watts Bar 2 PWR WH 4-Loop (ICECOND) Operational 1164.0 1973.0 2016.0 NaN 1973-09-01 2016-06-04 NaT Northern America Americas NaN 42.757016
747 United States Wolf Creek 1 PWR WH 4-Loop (DRY) Operational 1200.0 1977.0 1985.0 NaN 1977-05-31 1985-09-03 NaT Northern America Americas NaN 8.260096
748 United States Yankee Rowe 1 PWR WH (DRY) Dismantled 167.0 1957.0 1961.0 1991.0 1957-11-01 1961-07-01 1991-10-01 Northern America Americas 1991.0 3.663244
749 United States Zion 1 PWR WH (DRY) Dismantled 1040.0 1968.0 1973.0 1998.0 1968-12-01 1973-12-31 1998-02-13 Northern America Americas 1998.0 5.081451
750 United States Zion 2 PWR WH (DRY) Dismantled 1040.0 1968.0 1974.0 1998.0 1968-12-01 1974-09-17 1998-02-13 Northern America Americas 1998.0 5.793292

751 rows × 17 columns

total_constructed_by_subregion = input_df.groupby(['SubRegion', 'Region'])[['Begin building', 'Commercial operation', 'Closed']].count().reset_index().sort_values('Begin building', ascending=False).reset_index(drop=True)
total_constructed_by_subregion
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; }
.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}
</style>
SubRegion Region Begin building Commercial operation Closed
0 Eastern Asia Asia 181 147 34
1 Northern America Americas 165 159 52
2 Western Europe Europe 125 120 58
3 Eastern Europe Europe 122 94 29
4 Northern Europe Europe 67 64 45
5 Southern Asia Asia 42 31 2
6 Southern Europe Europe 21 15 13
7 Latin America and the Caribbean Americas 11 7 2
8 Western Asia Asia 10 5 1
9 Northern Africa Africa 3 0 0
10 Sub-Saharan Africa Africa 2 2 0
11 Central Asia Asia 1 1 1
12 South-eastern Asia Asia 1 0 1
total_constructed_by_country = input_df.groupby(['Country', 'SubRegion', 'Region'])[['Begin building', 'Commercial operation', 'Closed']].count().reset_index().sort_values('Begin building', ascending=False).reset_index(drop=True)
total_constructed_by_country
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; }
.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}
</style>
Country SubRegion Region Begin building Commercial operation Closed
0 United States Northern America Americas 140 134 46
1 China Eastern Asia Asia 81 55 0
2 France Western Europe Europe 69 68 12
3 Japan Eastern Asia Asia 62 59 26
4 Russia Eastern Europe Europe 62 47 10
5 United Kingdom Northern Europe Europe 46 44 35
6 Germany Western Europe Europe 39 36 39
7 India Southern Asia Asia 31 23 1
8 South Korea Eastern Asia Asia 30 27 2
9 Canada Northern America Americas 25 25 6
10 Ukraine Eastern Europe Europe 25 19 8
11 Sweden Northern Europe Europe 14 13 8
12 Spain Southern Europe Europe 14 10 7
13 Slovakia Eastern Europe Europe 9 8 3
14 Belgium Western Europe Europe 8 8 3
15 Bulgaria Eastern Europe Europe 8 6 4
16 Taiwan Eastern Asia Asia 8 6 6
17 Pakistan Southern Asia Asia 7 7 1
18 Italy Southern Europe Europe 6 4 6
19 Switzerland Western Europe Europe 6 6 2
20 Czech Republic Eastern Europe Europe 6 6 0
21 Finland Northern Europe Europe 5 5 0
22 Turkey Western Asia Asia 4 0 0
23 United Arab Emirates Western Asia Asia 4 3 0
24 Argentina Latin America and the Caribbean Americas 4 3 0
25 Belarus Eastern Europe Europe 4 2 2
26 Hungary Eastern Europe Europe 4 4 0
27 Brazil Latin America and the Caribbean Americas 3 2 0
28 Egypt Northern Africa Africa 3 0 0
29 Netherlands Western Europe Europe 2 2 1
30 Armenia Western Asia Asia 2 2 1
31 Bangladesh Southern Asia Asia 2 0 0
32 Cuba Latin America and the Caribbean Americas 2 0 2
33 Iran Southern Asia Asia 2 1 0
34 South Africa Sub-Saharan Africa Africa 2 2 0
35 Lithuania Northern Europe Europe 2 2 2
36 Mexico Latin America and the Caribbean Americas 2 2 0
37 Romania Eastern Europe Europe 2 2 0
38 Poland Eastern Europe Europe 2 0 2
39 Philippines South-eastern Asia Asia 1 0 1
40 Slovenia Southern Europe Europe 1 1 0
41 Austria Western Europe Europe 1 0 1
42 Kazakhstan Central Asia Asia 1 1 1

Number of constructed and operated reactors

World stats

num_building_started = input_df.groupby(['Begin building'])['Begin building'].count()
num_connected = input_df.groupby(['Commercial operation'])['Commercial operation'].count()
num_closed = input_df.groupby(['Closed'])['Closed'].count()
num_operated_closed = input_df.groupby(['Operated closed'])['Operated closed'].count()

max_building_started = num_building_started.max()
max_num_closed = num_closed.max()
ymax = (max_building_started + 4) // 5 * 5
ymin = (max_num_closed + 4) // 5 * 5

combined = pd.concat([
        num_building_started,
        num_connected,
        num_closed,
        num_operated_closed,
    ], axis=1)

combined = combined.reindex(years, fill_value=0)

combined['Commercial operation tot'] = combined['Commercial operation'].fillna(0).cumsum()
combined['Operated closed tot'] = combined['Operated closed'].fillna(0).cumsum()
combined['In operation'] = combined['Commercial operation tot'] - combined['Operated closed tot']

fig, ax = plt.subplots(2, 1, figsize=(11, 10))

ax1, ax2 = ax

combined['Begin building'].plot.bar(ax=ax1, label='Construction started')
(-combined['Closed']).plot.bar(ax=ax1, color='red', label='Closed')

title = 'World'
print(f'{title}:')
ax1.set_title(title)
ax1.set_xlabel(None)
format_years_ticks(ax1)
format_number_plants_ticks(ax1, ymin, ymax)
ax1.text(0, -ymin, copyright_text, fontsize=copyright_font_size, verticalalignment='bottom')
ax1.legend()

combined['In operation'].plot.bar(ax=ax2, label='Number in operation')
combined['Commercial operation'].plot.bar(ax=ax2, color='black', label='Operation started')
format_years_ticks(ax2)
#ax2.text(0, ax2.get_ylim()[1], copyright_text, fontsize=copyright_font_size, verticalalignment='top')
ax2.legend()

fig.tight_layout()
plt.show()
World:

png

Region stats

total_constructed_by_region = input_df.groupby(['Region'])[['Begin building', 'Commercial operation', 'Closed']].count().reset_index().sort_values('Begin building', ascending=False).reset_index(drop=True)

num_building_started = input_df.groupby(['Region', 'Begin building'])['Begin building'].count()
num_connected = input_df.groupby(['Region', 'Commercial operation'])['Commercial operation'].count()
num_closed = input_df.groupby(['Region', 'Closed'])['Closed'].count()
num_operated_closed = input_df.groupby(['Region', 'Operated closed'])['Operated closed'].count()

#top_regions = total_constructed_by_region[total_constructed_by_region['Begin building'] > 10]['Region'].to_list()
top_regions = total_constructed_by_region['Region'].to_list()

regions = sorted(c for c in input_df['Region'].unique() if c in num_building_started)

max_building_started = num_building_started.max()
max_num_closed = num_closed.max()
ymax = (max_building_started + 4) // 5 * 5
ymin = (max_num_closed + 4) // 5 * 5
tot_ymax_regions = 250  # TODO: calculate from data


for c in top_regions:
    combined = pd.concat([
        num_building_started[c],
        num_connected[c] if c in num_connected else pd.DataFrame(columns=['Commercial operation']),
        num_closed[c] if c in num_closed else pd.DataFrame(columns=['Closed']),
        num_operated_closed[c] if c in num_operated_closed else pd.DataFrame(columns=['Operated closed']),
    ], axis=1)
    
    combined = combined.reindex(years, fill_value=0)

    combined['Commercial operation tot'] = combined['Commercial operation'].fillna(0).cumsum()
    combined['Operated closed tot'] = combined['Operated closed'].fillna(0).cumsum()
    combined['In operation'] = combined['Commercial operation tot'] - combined['Operated closed tot']

    fig, ax = plt.subplots(2, 1, figsize=(11, 10))

    ax1, ax2 = ax

    combined['Begin building'].plot.bar(ax=ax1, label='Construction started')
    (-combined['Closed']).plot.bar(ax=ax1, color='red', label='Closed')

    title = f'{c} (UN M49)'
    print(f'{title}:')
    ax1.set_title(title)
    ax1.set_xlabel(None)
    format_years_ticks(ax1)
    format_number_plants_ticks(ax1, ymin, ymax)
    ax1.text(0, -ymin, copyright_text, fontsize=copyright_font_size, verticalalignment='bottom')
    ax1.legend()

    combined['In operation'].plot.bar(ax=ax2, label='Number in operation')
    combined['Commercial operation'].plot.bar(ax=ax2, color='black', label='Operation started')
    format_years_ticks(ax2)
    ax2.set_ylim(0, tot_ymax_regions)
    #ax2.text(0, ax2.get_ylim()[1], copyright_text, fontsize=copyright_font_size, verticalalignment='top')
    ax2.legend()


    fig.tight_layout()
    plt.show()
Europe (UN M49):

png

Asia (UN M49):

png

Americas (UN M49):

png

Africa (UN M49):

png

europe_df = input_df[(input_df['Region'] == 'Europe') & (input_df['SubRegion'] != 'Eastern Europe') & (input_df['SubRegion'] != 'Lithuania')]
num_building_started = europe_df.groupby(['Begin building'])['Begin building'].count()
num_connected = europe_df.groupby(['Commercial operation'])['Commercial operation'].count()
num_closed = europe_df.groupby(['Closed'])['Closed'].count()
num_operated_closed = europe_df.groupby(['Operated closed'])['Operated closed'].count()

max_building_started = num_building_started.max()
max_num_closed = num_closed.max()
ymax = (max_building_started + 4) // 5 * 5
ymin = (max_num_closed + 4) // 5 * 5

combined = pd.concat([
        num_building_started,
        num_connected,
        num_closed,
        num_operated_closed,
    ], axis=1)

combined = combined.reindex(years, fill_value=0)

combined['Commercial operation tot'] = combined['Commercial operation'].fillna(0).cumsum()
combined['Operated closed tot'] = combined['Operated closed'].fillna(0).cumsum()
combined['In operation'] = combined['Commercial operation tot'] - combined['Operated closed tot']

fig, ax = plt.subplots(2, 1, figsize=(11, 10))

ax1, ax2 = ax

combined['Begin building'].plot.bar(ax=ax1, label='Construction started')
(-combined['Closed']).plot.bar(ax=ax1, color='red', label='Closed')

title = 'Europe excluding Eastern Europe and ex-USSR countries'
print(f'{title}:')
ax1.set_title(title)
ax1.set_xlabel(None)
format_years_ticks(ax1)
format_number_plants_ticks(ax1, ymin, ymax)
ax1.text(0, -ymin, copyright_text, fontsize=copyright_font_size, verticalalignment='bottom')
ax1.legend()

combined['In operation'].plot.bar(ax=ax2, label='Number in operation')
combined['Commercial operation'].plot.bar(ax=ax2, color='black', label='Operation started')
format_years_ticks(ax2)
ax2.set_ylim(0, tot_ymax_regions)
#ax2.text(0, ax2.get_ylim()[1], copyright_text, fontsize=copyright_font_size, verticalalignment='top')
ax2.legend()

fig.tight_layout()
plt.show()
Europe excluding Eastern Europe and ex-USSR countries:

png

Subregion stats

num_building_started = input_df.groupby(['SubRegion', 'Begin building'])['Begin building'].count()
num_connected = input_df.groupby(['SubRegion', 'Commercial operation'])['Commercial operation'].count()
num_closed = input_df.groupby(['SubRegion', 'Closed'])['Closed'].count()
num_operated_closed = input_df.groupby(['SubRegion', 'Operated closed'])['Operated closed'].count()

sub_regions = sorted(c for c in input_df['SubRegion'].unique() if c in num_building_started)
#top_regions = total_constructed_by_subregion[total_constructed_by_subregion['Begin building'] > 10]['SubRegion'].to_list()
top_regions = total_constructed_by_subregion['SubRegion'].to_list()

max_building_started = num_building_started.max()
max_num_closed = num_closed.max()
ymax = (max_building_started + 4) // 5 * 5
ymin = (max_num_closed + 4) // 5 * 5


for c in top_regions:
    combined = pd.concat([
        num_building_started[c],
        num_connected[c] if c in num_connected else pd.DataFrame(columns=['Commercial operation']),
        num_closed[c] if c in num_closed else pd.DataFrame(columns=['Closed']),
        num_operated_closed[c] if c in num_operated_closed else pd.DataFrame(columns=['Operated closed']),
    ], axis=1)
    
    combined = combined.reindex(years, fill_value=0)

    combined['Commercial operation tot'] = combined['Commercial operation'].fillna(0).cumsum()
    combined['Operated closed tot'] = combined['Operated closed'].fillna(0).cumsum()
    combined['In operation'] = combined['Commercial operation tot'] - combined['Operated closed tot']

    fig, ax = plt.subplots(2, 1, figsize=(11, 10))

    ax1, ax2 = ax

    combined['Begin building'].plot.bar(ax=ax1, label='Construction started')
    (-combined['Closed']).plot.bar(ax=ax1, color='red', label='Closed')

    title = f'{c} (UN M49)'
    print(f'{title}:')
    ax1.set_title(title)
    ax1.set_xlabel(None)
    format_years_ticks(ax1)
    format_number_plants_ticks(ax1, ymin, ymax)
    ax1.text(0, -ymin, copyright_text, fontsize=copyright_font_size, verticalalignment='bottom')
    ax1.legend()

    combined['In operation'].plot.bar(ax=ax2, label='Number in operation')
    combined['Commercial operation'].plot.bar(ax=ax2, color='black', label='Operation started')
    format_years_ticks(ax2)
    ax2.set_ylim(0, tot_ymax_regions)
    #ax2.text(0, ax2.get_ylim()[1], copyright_text, fontsize=copyright_font_size, verticalalignment='top')
    ax2.legend()


    fig.tight_layout()
    plt.show()
Eastern Asia (UN M49):

png

Northern America (UN M49):

png

Western Europe (UN M49):

png

Eastern Europe (UN M49):

png

Northern Europe (UN M49):

png

Southern Asia (UN M49):

png

Southern Europe (UN M49):

png

Latin America and the Caribbean (UN M49):

png

Western Asia (UN M49):

png

Northern Africa (UN M49):

png

Sub-Saharan Africa (UN M49):

png

Central Asia (UN M49):

png

South-eastern Asia (UN M49):

png

Country stats

num_building_started = input_df.groupby(['Country', 'Begin building'])['Begin building'].count()
num_connected = input_df.groupby(['Country', 'Commercial operation'])['Commercial operation'].count()
num_closed = input_df.groupby(['Country', 'Closed'])['Closed'].count()
num_operated_closed = input_df.groupby(['Country', 'Operated closed'])['Operated closed'].count()

countries = sorted(c for c in input_df['Country'].unique() if c in num_building_started)
#top_countries = total_constructed_by_country[total_constructed_by_country['Begin building'] >= 10]['Country'].to_list()
top_countries = total_constructed_by_country['Country'].to_list()

max_building_started = num_building_started.max()
max_num_closed = num_closed.max()
ymax = (max_building_started + 4) // 5 * 5
ymin = (max_num_closed + 4) // 5 * 5
tot_ymax = 120  # TODO: calculate from data


for c in top_countries:
    combined = pd.concat([
        num_building_started[c],
        num_connected[c] if c in num_connected else pd.DataFrame(columns=['Commercial operation']),
        num_closed[c] if c in num_closed else pd.DataFrame(columns=['Closed']),
        num_operated_closed[c] if c in num_operated_closed else pd.DataFrame(columns=['Operated closed']),
    ], axis=1)
    
    combined = combined.reindex(years, fill_value=0)

    combined['Commercial operation tot'] = combined['Commercial operation'].fillna(0).cumsum()
    combined['Operated closed tot'] = combined['Operated closed'].fillna(0).cumsum()
    combined['In operation'] = combined['Commercial operation tot'] - combined['Operated closed tot']

    fig, ax = plt.subplots(2, 1, figsize=(11, 10))

    ax1, ax2 = ax

    combined['Begin building'].plot.bar(ax=ax1, label='Construction started')
    (-combined['Closed']).plot.bar(ax=ax1, color='red', label='Closed')

    title = c
    print(f'{title}:')
    ax1.set_title(title)
    ax1.set_xlabel(None)
    format_years_ticks(ax1)
    format_number_plants_ticks(ax1, ymin, ymax)
    ax1.text(0, -ymin, copyright_text, fontsize=copyright_font_size, verticalalignment='bottom')
    ax1.legend()

    combined['In operation'].plot.bar(ax=ax2, label='Number in operation')
    combined['Commercial operation'].plot.bar(ax=ax2, color='black', label='Operation started')
    format_years_ticks(ax2)
    ax2.set_ylim(0, tot_ymax)
    #ax2.text(0, ax2.get_ylim()[1], copyright_text, fontsize=copyright_font_size, verticalalignment='top')
    ax2.legend()

    fig.tight_layout()
    plt.show()
United States:

png

China:

png

France:

png

Japan:

png

Russia:

png

United Kingdom:

png

Germany:

png

India:

png

South Korea:

png

Canada:

png

Ukraine:

png

Sweden:

png

Spain:

png

Slovakia:

png

Belgium:

png

Bulgaria:

png

Taiwan:

png

Pakistan:

png

Italy:

png

Switzerland:

png

Czech Republic:

png

Finland:

png

Turkey:

png

United Arab Emirates:

png

Argentina:

png

Belarus:

png

Hungary:

png

Brazil:

png

Egypt:

png

Netherlands:

png

Armenia:

png

Bangladesh:

png

Cuba:

png

Iran:

png

South Africa:

png

Lithuania:

png

Mexico:

png

Romania:

png

Poland:

png

Philippines:

png

Slovenia:

png

Austria:

png

Kazakhstan:

png

Never opened reactors

# Never opened
never_opened_df = input_df[input_df['Commercial operation'].isna() & input_df['Begin building'].notna() & input_df['Closed'].notna()].sort_values('Closed')

num_building_started = never_opened_df.groupby(['Begin building'])['Begin building'].count()
num_closed = never_opened_df.groupby(['Closed'])['Closed'].count()

combined = pd.concat([
        num_building_started,
        num_closed,
    ], axis=1)

combined = combined.reindex(years, fill_value=0)

fig, ax = plt.subplots(figsize=(11, 5))

combined['Begin building'].plot.bar(ax=ax, label='Construction started')
(-combined['Closed']).plot.bar(ax=ax, color='red', label='Closed')

title = 'Never operated reactors'
print(f'{title}:')
ax.set_title(title)
ax.set_xlabel(None)
format_years_ticks(ax)
ax.yaxis.set_major_formatter(lambda val, pos: int(val))
ax.text(0, ax.get_ylim()[0], copyright_text, fontsize=copyright_font_size, verticalalignment='bottom')
ax.legend()

fig.tight_layout()
plt.show()
Never operated reactors:

png

never_opened_df.groupby(['Country', 'Closed'])['Closed'].count().sort_values(ascending=False)
Country        Closed
Spain          1984.0    4
United States  1984.0    3
Belarus        1987.0    2
Cuba           1992.0    2
Germany        1990.0    2
Italy          1988.0    2
Poland         1990.0    2
Taiwan         2014.0    2
Ukraine        1987.0    2
               1990.0    2
United States  1983.0    2
Austria        1978.0    1
Germany        1985.0    1
Philippines    1986.0    1
Sweden         1970.0    1
Name: Closed, dtype: int64
never_opened_df.groupby(['Country', 'Begin building'])['Begin building'].count().sort_values(ascending=False)
Country        Begin building
United States  1975.0            4
Poland         1982.0            2
Ukraine        1988.0            2
               1984.0            2
Germany        1983.0            2
Italy          1982.0            2
Taiwan         1999.0            2
Belarus        1983.0            2
Spain          1972.0            2
               1975.0            2
Sweden         1965.0            1
Austria        1972.0            1
Philippines    1976.0            1
Germany        1972.0            1
Cuba           1985.0            1
               1983.0            1
United States  1977.0            1
Name: Begin building, dtype: int64

Construction time

construction_time = input_df.groupby(['Begin building'])['Construction time'].agg(['min', 'median', 'max']).reindex(years, fill_value=0)

fig, ax = plt.subplots(figsize=(11, 5))

construction_time.plot.bar(ax=ax, width=0.8)

title = 'Years of construction time by the year when construction started - World'
print(f'{title}:')
ax.set_title(title)
ax.set_xlabel(None)
format_years_ticks(ax)
ax.yaxis.set_major_formatter(lambda val, pos: int(val))
ax.yaxis.set_major_locator(ticker.MultipleLocator(5))
ax.text(0, ax.get_ylim()[1] - 0.1, copyright_text, fontsize=copyright_font_size, verticalalignment='top')
ax.legend()

fig.tight_layout()
plt.show()
Years of construction time by the year when construction started - World:

png

top_countries = total_constructed_by_country['Country'].to_list()
construction_time = input_df.groupby(['Country', 'Begin building'])['Construction time'].agg(['min', 'median', 'max'])
ymax = construction_time.max(axis=None) + 1

for c in top_countries:
    df = construction_time[construction_time.index.get_level_values(0) == c].droplevel(0).reindex(years, fill_value=0)
    
    fig, ax = plt.subplots(figsize=(11, 5))

    df.plot.bar(ax=ax, width=0.8)

    title = f'Years of construction time by the year when construction started - {c}'
    print(title)
    ax.set_title(title)
    ax.set_xlabel(None)
    format_years_ticks(ax)

    ax.yaxis.set_major_formatter(lambda val, pos: int(abs(val)))
    ax.yaxis.set_major_locator(ticker.MultipleLocator(5))

    ax.set_ylim(0, ymax)
    ax.text(0, ax.get_ylim()[1], copyright_text, fontsize=copyright_font_size, verticalalignment='top')
    ax.legend()

    fig.tight_layout()
    plt.show()
Years of construction time by the year when construction started - United States

png

Years of construction time by the year when construction started - China

png

Years of construction time by the year when construction started - France

png

Years of construction time by the year when construction started - Japan

png

Years of construction time by the year when construction started - Russia

png

Years of construction time by the year when construction started - United Kingdom

png

Years of construction time by the year when construction started - Germany

png

Years of construction time by the year when construction started - India

png

Years of construction time by the year when construction started - South Korea

png

Years of construction time by the year when construction started - Canada

png

Years of construction time by the year when construction started - Ukraine

png

Years of construction time by the year when construction started - Sweden

png

Years of construction time by the year when construction started - Spain

png

Years of construction time by the year when construction started - Slovakia

png

Years of construction time by the year when construction started - Belgium

png

Years of construction time by the year when construction started - Bulgaria

png

Years of construction time by the year when construction started - Taiwan

png

Years of construction time by the year when construction started - Pakistan

png

Years of construction time by the year when construction started - Italy

png

Years of construction time by the year when construction started - Switzerland

png

Years of construction time by the year when construction started - Czech Republic

png

Years of construction time by the year when construction started - Finland

png

Years of construction time by the year when construction started - Turkey

png

Years of construction time by the year when construction started - United Arab Emirates

png

Years of construction time by the year when construction started - Argentina

png

Years of construction time by the year when construction started - Belarus

png

Years of construction time by the year when construction started - Hungary

png

Years of construction time by the year when construction started - Brazil

png

Years of construction time by the year when construction started - Egypt

png

Years of construction time by the year when construction started - Netherlands

png

Years of construction time by the year when construction started - Armenia

png

Years of construction time by the year when construction started - Bangladesh

png

Years of construction time by the year when construction started - Cuba

png

Years of construction time by the year when construction started - Iran

png

Years of construction time by the year when construction started - South Africa

png

Years of construction time by the year when construction started - Lithuania

png

Years of construction time by the year when construction started - Mexico

png

Years of construction time by the year when construction started - Romania

png

Years of construction time by the year when construction started - Poland

png

Years of construction time by the year when construction started - Philippines

png

Years of construction time by the year when construction started - Slovenia

png

Years of construction time by the year when construction started - Austria

png

Years of construction time by the year when construction started - Kazakhstan

png