Skip to content

Instantly share code, notes, and snippets.

View dkapitan's full-sized avatar
☸️

Daniel Kapitan dkapitan

☸️
View GitHub Profile
@dkapitan
dkapitan / cibg-big-register.py
Created March 3, 2022 10:07
Using zeep to query SOAP
from zeep import Client
client = Client("https://webservices.cibg.nl/Ribiz/OpenbaarV4.asmx?wsdl")
client.service.ListHcpApprox4(WebSite="Ribiz", Name="Kerkhoven", Initials="M")
@dkapitan
dkapitan / sparse_matrix_to_tensor.py
Created January 23, 2022 22:25
Convert SciPy sparse matrix to tf.sparse.SparseTensor
def sparse_matrix_to_tensor(X):
"""Transforms SciPy sparse matrix to tensorflow.sparse.SparseTensor."""
row_nnz = np.diff(X.indptr)
indices = np.asarray([[row_i, col_i]
for row_i, nnz in enumerate(row_nnz)
for col_i in range(nnz)], dtype=np.int64)
values = X.data
return SparseTensor(indices=indices, values=values, dense_shape=X.shape)
@dkapitan
dkapitan / config-wsl-ubuntu.md
Last active January 8, 2022 14:37
configuration wsl ubuntu

Base image

  • install Windows Terminal
  • install wsl
  • install Ubuntu
  • sudo apt update && sudo apt upgrade
  • install Homebrew
  • install pyenv
  • install oh-my-posh
  • install jump
@dkapitan
dkapitan / make_polynomial.py
Created November 21, 2021 19:10
Polynomial
def make_polynomial(dataframe, degree=MAX_DEGREE):
"""Function for creating higher-order polynomial features from dataframe.
Dataframe df should be like [Y, X1, X2, .. Xi].
Returns dataframe polynomial features of X1 ... Xi up to degree polynomials."""
df = dataframe.copy()
cols = df.columns[1:]
for i in range(2, degree + 1):
for col in cols:
@dkapitan
dkapitan / stelselcatalogus.ttl
Created September 30, 2021 06:59
Stelselcatalogus
This file has been truncated, but you can view the full file.
# baseURI: http://opendata.stelselcatalogus.nl/id/dataset/sc
# imports: http://purl.org/dc/elements/1.1/
# imports: http://rdfs.org/ns/void
# imports: http://www.w3.org/2004/02/skos/core
@prefix adms: <http://www.w3.org/ns/adms#> .
@prefix begrip_banken: <http://opendata.stelselcatalogus.nl/banken/id/begrip/> .
@prefix begrip_bgt: <http://opendata.stelselcatalogus.nl/bgt/id/begrip/> .
@prefix begrip_bri: <http://opendata.stelselcatalogus.nl/bri/id/begrip/> .
@prefix begrip_brk: <http://opendata.stelselcatalogus.nl/brk/id/begrip/> .
@dkapitan
dkapitan / ISSUE_TEMPLATE.md
Created September 24, 2021 08:46
GitHub templates

Title

When released, this story will ENTER TEXT HERE.

Description

As a ENTER ROLE I want ENTER GOAL, so that ENTER REASON(S).

Requirements

@dkapitan
dkapitan / kwb-datasets.py
Created July 29, 2021 09:44
cbs statline
KWB = {
2016: "83487NED",
2017: "83765NED",
2018: "84286NED",
2019: "84583NED",
2020: "84799NED"
}
@dkapitan
dkapitan / python-versions.md
Last active May 11, 2021 10:52
Python 3 main versions - highlights
  • 3.6: f-strings
  • 3.7: async and await; dataclasses
  • 3.8: assignment expression (:=)
  • 3.9: type hinting generics in standard library
@dkapitan
dkapitan / blog-post.md
Created January 30, 2021 10:27
comet-chart-flight-delays-post

Zan Armstrong's comet chart has been on my list of hobby projects for a while now. I think it is an elegant solution to visualize statistical mix effects and address Simpson's paradox, and particularly useful when working with longitudinal data involving different sub-populations. Recently I found a good excuse to spend some time to actually use it as part of a exploratory data analysis on a project.

Since I mostly work in Python and have recently fallen in love with Altair - for the same reasons as Fernando explains here - I wondered how the comet chart could be implemented using the grammar of interactive graphics. It took me a while to figure out how to actually plot the c

@dkapitan
dkapitan / comet-chart-flight-delays.py
Last active January 30, 2021 10:26
Comet charts in Python: visualizing statistical mix effects and Simpson's paradox in Altair
import altair as alt
import pandas as pd
import vega_datasets
# Use airline data to assess statistical mix effects of delays
flights = vega_datasets.data.flights_20k()
aggregation = dict(
number_of_flights=("destination", "count"),
mean_delay=("delay", "mean"),