Skip to content

Instantly share code, notes, and snippets.

View braaannigan's full-sized avatar

Liam Brannigan braaannigan

View GitHub Profile
@braaannigan
braaannigan / interactive_plot.py
Last active March 23, 2018 01:41
Interactive plots with holoviews in a jupyter notebook - needs to be in two separate code cells, see text for details
# The following must be executed in a jupyter notebook rather than a shell environment.
# Use numpy to work with arrays
import numpy as np
# Use scipy.stats to do plot some statistical data
import scipy.stats as stats
import holoviews as hv
# Holoviews builds on top of either the Matplotlib or Bokeh plotting library. Choose to use Bokeh
# in these plots as interactive plots work very well with Bokeh
hv.notebook_extension('bokeh')
@braaannigan
braaannigan / queries.py
Last active April 19, 2022 14:45
Query optimisation with Polars in python
import pandas as pd
import polars as pl
import dask.dataframe as dd
# You can get the data from here:
# s3://coiled-datasets/h2o/G1_1e8_1e2_0_0/csv/G1_1e8_1e2_0_0.csv
fl = "data/G1_1e8_1e2_0_0.csv"
# Pandas and Dask examples based on this blog post
# https://coiled.io/blog/speed-up-pandas-query-10x-with-dask/
from datetime import timedelta, datetime
import polars as pl
# Make a dataframe with a one hour time series at 10-min intervals for group "a"
df = (
pl.DataFrame(
{'date':pl.date_range(start,stop,timedelta(minutes=10))
})
.with_column(