In [1]:
import pandas as pd
In [2]:
df = pd.read_csv('empires.csv')
df.head()
Out[2]:
Empire Origin Capital From To Duration Note
0 Achaemenid Empire Iran Various, including Pasargadae, Ecbatana, Perse... 550 BC 330 BC 220 The first Persian empire, and the largest one ...
1 Afsharid Dynasty Iran Mashhad 1736 1796 60 Founded by Nader Shah, at its peak expanded Pe...
2 Abbasid Caliphate Iraq Baghdad, Raqqa, Kufa, Samarra, Anbar 750 1258 508 Successor of the Umayyad Caliphate.
3 Ahom Dynasty North East India Charaideo, Garhgaon, Rangpur (Ahom capital), J... 1228 1838 610 It is well known for maintaining its sovereign...
4 Akkadian Empire Sumer Akkad 2300 BC 2200 BC 100 The Second Empire On The Earth.
In [3]:
# thanks regexr.com
pat = "(\d+)\s*BC"
repl = r"-\1"

for c in ["From", "To"]:
    df[c] = df[c].str.replace(pat, repl)
    df[c] = df[c].astype(int)
    # because AD/BC has no year 0
    df[c] = df[c].apply(lambda x: x+1 if x < 0 else x)
In [4]:
# the calculated duration here is different from the Duration column provided,
# probably because I made some ~arbitrary cleanup choices in the original file.
df['calc_duration'] = df['To'] - df['From']
df['years_ago_ended'] = 2020 - df['To']
In [5]:
# looking for a good name for this.
df['years_to_inflection'] = df['calc_duration'] - df['years_ago_ended']
In [6]:
output = (
    df[
        df.years_to_inflection.abs() < 50
    ]
    .sort_values('years_to_inflection')
    .reset_index()[
        [
            'Empire', 'Origin', 'From', 'To', 'calc_duration', 'years_ago_ended','years_to_inflection'
        ]
    ]
)
output
Out[6]:
Empire Origin From To calc_duration years_ago_ended years_to_inflection
0 Safavid dynasty Persia 1501 1736 235 284 -49
1 Georgian Empire Georgia 1008 1490 482 530 -48
2 Zulu Empire South Africa 1818 1897 79 123 -44
3 Mali Empire West Africa 1235 1610 375 410 -35
4 Mughal Empire India 1526 1758 232 262 -30
5 Toungoo dynasty Toungoo 1510 1752 242 268 -26
6 Italian Empire Italy 1885 1943 58 77 -19
7 Sokoto Caliphate West Africa 1804 1903 99 117 -18
8 Bamana Empire West Africa 1712 1861 149 159 -10
9 Duchy of Savoy Savoy 1416 1713 297 307 -10
10 Omani Empire Oman 1698 1856 158 164 -6
11 Konbaung dynasty Myanmar 1752 1885 133 135 -2
12 Belgian colonial empire Belgium 1901 1962 61 58 3
13 Empire of Japan Japan 1868 1947 79 73 6
14 Pahlavi dynasty Persia 1925 1979 54 41 13
15 British Raj Indian Subcontinent 1858 1947 89 73 16
16 Empire of Great Fulo Senegal 1514 1776 262 244 18
17 Kingdom of Prussia Germany 1701 1871 170 149 21
18 Lakota people Great Plains 1700 1877 177 143 34
19 Qajar dynasty[citation needed] Persia 1794 1925 131 95 36
20 Khmer Empire Cambodia 802 1431 629 589 40
In [7]:
output.to_html('output_table.html')
In [ ]: