This file contains hidden or 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
| import requests | |
| import pandas as pd | |
| import itertools | |
| def get_table_ids(shortname: str) -> list[str]: | |
| shortname_content = requests.get("https://data.ssb.no/api/pxwebapi/v2-beta/navigation/{shortname}").json() | |
| return [x for x in [table.get("id") for table in shortname_content.get("folderContents")] if x.isdigit() and len(x) == 5] | |
| def table_dataframe(tableid: str) -> pd.DataFrame: |
This file contains hidden or 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
| import { QuartzTransformerPlugin } from "../types" | |
| const secret_regex = new RegExp(/(---secret[\s\S]*?secret---)/, "g") | |
| export const SecretRemover: QuartzTransformerPlugin = () => { | |
| return { | |
| name: "SecretRemover", | |
| textTransform(_ctx, src) { | |
| src = src.toString() | |
| src = src.replaceAll(secret_regex, (value, ...capture) => { |
This file contains hidden or 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
| import pandas as pd | |
| from pandas.io.sas.sas7bdat import SAS7BDATReader | |
| def proc_contents(path: str) -> pd.DataFrame: | |
| sasfile = SAS7BDATReader(path, | |
| convert_dates=False, | |
| blank_missing=False, | |
| convert_text=False, | |
| chunksize=1, | |
| ) |
This file contains hidden or 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
| import pandas as pd | |
| class Wrapper: | |
| def __init__(self, df: pd.DataFrame): | |
| self.data = df | |
| def __str__(self): | |
| return str(self.data.info()) | |
| def __repr__(self): |
This file contains hidden or 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
| import json | |
| labels_script = """ | |
| fnr = 'Fødselsnummer' | |
| snr_nudb = 'Snr' | |
| kjoenn = 'kjønn (lages ut fra snr)' | |
| fodt_aar = 'fødselsår yyyy (lages ut fra snr)' | |
| fodt_dato = 'fødselsdato yyyymmdd (hentes fra befolkningsfila)' | |
| fodato = 'Oppholdsdato første opphold i Norge yyyymmdd (hentes fra befolkningsfila)' | |
| fodeland = 'Fødeland (hentes fra befolkningsfila)' |
This file contains hidden or 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
| colors = [ | |
| "#1a9d49", | |
| "#3396d2", | |
| "#9582bb", | |
| "#f26539", | |
| "#d2bc2a", | |
| "#6f9090"] | |
| alpha = 0.65 | |
| # Convert colors to rgba, and give them the set opacity |
This file contains hidden or 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
| from copy import deepcopy | |
| from collections import Counter | |
| def restructure_belop(inp: dict) -> dict: | |
| skjemaer_ny = deepcopy(skjemaer) | |
| for skjema_gml, skjema_ny in zip(skjemaer, skjemaer_ny): | |
| counts = Counter([elem["funksjon/kapittel"] for elem in skjema_gml["regnskap"]]) | |
| code_groups = [k for k, v in counts.items() if v > 1] | |
| for code in code_groups: | |
| elems = [x for x in skjema_gml["regnskap"] if x["funksjon/kapittel"] == code] | |
| for elem in elems: |
This file contains hidden or 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
| let | |
| tableId = "NBA040", | |
| PostContents = "{ | |
| ""query"": [ | |
| { | |
| ""code"": ""AgeGroup"", | |
| ""selection"": { | |
| ""filter"": ""item"", | |
| ""values"": [ | |
| ""Y15-74"" |
This file contains hidden or 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
| import matplotlib.pyplot as plt | |
| import seaborn as sns | |
| # Initialize seaborn object | |
| d = sns.kdeplot(data = dataset, shade = True, shade_lowest = False, cmap = 'vlag') | |
| # Set some attributes on the seaborn-object | |
| d.set(ylim=(0,55), xlabel = 'Two first numbers of NACE', ylabel = 'Number of Employees per company') | |
| # Display the visual | |
| plt.show() |
This file contains hidden or 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
| import matplotlib.pyplot as plt | |
| import seaborn as sns | |
| # Limit data | |
| dataset = dataset[dataset.NACE_first.isin([1, 2, 3])] | |
| # Initialize seaborn object | |
| v = sns.violinplot(data = dataset, x = 'NACE_first', y = 'employee_points', palette = 'Set3', inner = 'quart') | |
| # Set some attributes on the seaborn-object | |
| v.set(ylim=(0,120), xlabel = 'First Nace Number', ylabel = 'Number of Employees per company') | |
| # Remove some of the borders |
NewerOlder