Skip to content

Instantly share code, notes, and snippets.

View rcsmit's full-sized avatar

Rene Smit rcsmit

View GitHub Profile
@rcsmit
rcsmit / read_pdf_convert_to_xls.py
Created March 31, 2025 15:59
read_pdf_convert_to_xls.py
# Read a PDF and convert it to an XLS
# Tested on Bijlage B - Wob-deelbesluit 'Vaccinaties en medicatie oktober 2020'
# Not tested 100%
# inspired by https://x.com/Transparangst/status/1906717209423974689
def read_directly_from_pdf():
# read a file
import pandas as pd
import numpy as np
import math
import numpy as np
import matplotlib.pyplot as plt
def binary_search_steps(target, max_num):
"""Simulate binary search and return number of steps needed"""
@rcsmit
rcsmit / stacked_range_bar_chart.py
Last active November 23, 2024 05:18
stacked range bar chart
import pandas as pd
import streamlit as st
import plotly.graph_objects as go
import matplotlib.pyplot as plt
# stacked range bar chart
# as proposed by https://www.youtube.com/watch?v=5zBg9pH_6bE
# by Rene Smit (@rcsmit), with help from Github Co Pilot (GPT 4o)
@rcsmit
rcsmit / verwachte_sterfte_2020_2024.py
Last active November 11, 2024 06:29
verwachte_sterfte_2020_2024
# We berekenen de sterfte in 2020-2024 aan de hand van de sterftekansen per leeftijdsgroep (5jr, Eurostats) in 2019 en
# de bevolkingsgrootte in 2020-2024(CBS)
# Naar aanleiding van https://twitter.com/PeeNee2/status/1855384448478609656
import pandas as pd
# Load the data from CSV files
sterfte_df = pd.read_csv("https://raw.githubusercontent.com/rcsmit/COVIDcases/refs/heads/main/input/sterfte_eurostats_NL.csv")
bevolking_df = pd.read_csv("https://raw.githubusercontent.com/rcsmit/COVIDcases/refs/heads/main/input/bevolking_leeftijd_NL.csv", delimiter=";")
sterfte_df['jaar'] = sterfte_df['TIME_PERIOD'].str[:4].astype(int)
@rcsmit
rcsmit / gist:afc46478b9dea858aa505e614c45aed9
Last active October 26, 2024 11:46
donkeyshot_simulation_reproduction_ratio.py
import numpy as np
from scipy.integrate import odeint
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
@rcsmit
rcsmit / gist:42cf7bedc73d8741725aa9b815772d5a
Last active October 9, 2024 23:30
jpg to pdf - streamlit
import os
import time
import streamlit as st
from PIL import Image, ExifTags
from io import BytesIO
import pytesseract
import re
import os
# based on https://www.youtube.com/watch?v=RPN-HxvAQnQ
@rcsmit
rcsmit / get_eurostat_data.py
Last active June 24, 2024 12:33
Get from Eurostat : Deaths by week, sex and 5-year age group
def get_data_eurostat():
"""Get from Eurostat : Deaths by week, sex and 5-year age group
Data from https://ec.europa.eu/eurostat/databrowser/product/view/demo_r_mwk_05?lang=en
https://ec.europa.eu/eurostat/databrowser/bookmark/fbd80cd8-7b96-4ad9-98be-1358dd80f191?lang=en
https://ec.europa.eu/eurostat/api/dissemination/sdmx/2.1/dataflow/ESTAT/DEMO_R_MWK_05/1.0?references=descendants&detail=referencepartial&format=sdmx_2.1_generic&compressed=true
Returns:
df: dataframe with weekly mortality in 5 year tranches
DATAFLOW LAST UPDATE freq age sex ... OBS_VALUE OBS_FLAG age_sex jaar weeknr
@rcsmit
rcsmit / small_ci_statsmodels
Created June 11, 2024 14:49
Why is the CI-width so small?
import pandas as pd
import streamlit as st
import plotly.graph_objects as go
import numpy as np
import statsmodels.api as sm
// output: https://twitter.com/rcsmit/status/1800539585841344854
def test():
# recreating https://twitter.com/NateB_Panic/status/1636811443612860417/photo/1
import numpy as np
import plotly
import plotly.graph_objects as go
import numpy as np
p_values = [0.01, 0.05,0.1,0.2, 0.3, 0.5] # set the values of p
x = np.arange(0, 30, 1) # generate an array of x values from 0 to 10
""" A script to calculate the loss or gain after x months working in a year with a montly salary of y
This calculation is a simplification
Goal is to learn to work with OOP and make the script pythonic as much as possible.
TODO : calculate the total capital after z years, with taking inflation in account
Returns:
A dataframe like this: