Skip to content

Instantly share code, notes, and snippets.

View gdementen's full-sized avatar

Gaëtan de Menten gdementen

  • Federal Planning Bureau
  • Belgium
  • 03:46 (UTC +01:00)
View GitHub Profile
@gdementen
gdementen / frozen.py
Last active March 19, 2023 18:18
qtpy frozen column example
# taken from
# http://blindvic.blogspot.be/2010/12/frozen-column-example-pyqt4-python3.html
# conversion to qtpy, russian comments removal and a few minor improvements done by Gaëtan de Menten
# That blog post was itself inspired from
# http://python.su/forum/viewtopic.php?id=7346
# see also
# http://objexx.com/labs.Efficient-Qt-Frozen-Columns-and-Rows.html
# to make it more efficient for large tables
@gdementen
gdementen / dynamic_factor_range_test.html
Created February 5, 2019 14:33
attempt to create a bokeh categorical plot with dynamic factors
<!DOCTYPE HTML>
<html>
<head>
<title>Sandbox</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
@gdementen
gdementen / lazyframe_pivot.py
Last active October 13, 2025 14:25
Pivot for polars LazyFrame
import polars as pl
def lazy_pivot(lf, on, index, values, aggregate_function=None, maintain_order=True):
on = pl.col(on)
index = pl.col(index)
values = pl.col(values)
unq_values = lf.select(on).unique(maintain_order=maintain_order).collect(engine='streaming').to_series().to_list()
if aggregate_function is None:
# FIXME: this does not replicate eager pivot default value which raises when there are several values in a cell
aggregate_function = 'first'