Explore
Groups
No topics yet. Start the conversation.
Description
The below description is supplied in free-text by the user
Historical Unemployment rates in the Large EU countries
A short example that can be run on any server or computer, rotating different views on the historical unemployment in large european countries
import time
import random
import numpy as np
import pandas as pd
from novem import Plot
# get IMF World Economic Outlook
weo = pd.read_csv(
"https://www.imf.org/-/media/Files/Publications/WEO/WEO-Database/2021/WEOOct2021all.ashx",
encoding="windows-1252",
sep="\t"
)
# define the large eu using IMF 3 letter codes
cty = ['FRA','DEU','GBR','POL','ITA']
# define our subject
subject = ['Unemployment rate']
# construct our filter
flt = pd.concat([
pd.DataFrame(cty),
pd.DataFrame(subject),
], axis=1).fillna(method='pad')
flt.columns = [
'ISO',
'Subject Descriptor',
]
# filter data
cdata = pd.merge(weo, flt, how='inner')
# select numeric data ranges and clean up data
cdata = cdata.set_index('Country') \
.iloc[:, 9:-1] \
.apply(lambda x: x.apply(float), axis=1)
# transpose and filter for years we care about
data = cdata.T['1980':'2021']
# construct novem plot
sbar = Plot('imf_weo_unemployment_hist_1',
name='Historical Unemployment rates in the Large EU countries',
type='sbar'
)
# write data to reset the plot
data.pipe(sbar)
def swap_random(seq):
idx = range(len(seq))
i1, i2 = random.sample(idx, 2)
seq[i1], seq[i2] = seq[i2], seq[i1]
while 1:
# get novem url
print(f'Updating data: {sbar.url}') # https://novem.no/p/ywqOv
# remove a random column
time.sleep(5)
col = random.choice(data.columns)
cand = data.drop(columns=[col])
cand.pipe(sbar)
time.sleep(3)
data.pipe(sbar)
# swap two random columns
time.sleep(5)
cand = data.copy()
ncl = list(cand.columns)
swap_random(ncl)
cand=cand.reindex(columns=ncl)
cand.pipe(sbar)
time.sleep(3)
data.pipe(sbar)
# switch between stacked and grouped
time.sleep(5)
sbar.type = 'gbar'
time.sleep(3)
sbar.type = 'sbar'
# filter last 10 rows
time.sleep(5)
cand = data.copy()
cand.iloc[:-10].pipe(sbar)
time.sleep(3)
data.pipe(sbar)
# sort by highest to lowest (total)
time.sleep(5)
cand = data.copy()
cand['sum'] = cand.sum(axis=1)
cand.sort_values(by='sum', ascending=False).drop(columns='sum').pipe(sbar)
time.sleep(3)
data.pipe(sbar)
# send data to novem
#cand.pipe(sbar)
time.sleep(5)