Skip to content

Instantly share code, notes, and snippets.

View janpipek's full-sized avatar
🤔
...

Jan Pipek janpipek

🤔
...
View GitHub Profile
@janpipek
janpipek / normalize_series.py
Created August 16, 2022 16:59
Normalize series
import numbers
from typing import Literal, Optional, Union
import numpy as np
import pandas as pd
def normalize_series(
series: pd.Series,
*,
@janpipek
janpipek / create_bookshelf.py
Last active January 21, 2021 13:46
Home bookshelf design
import matplotlib.pyplot as plt
import numpy as np
from draw import *
from data import *
fig, ax = plt.subplots(figsize=(20, 12))
nonwallcolor = "#c0c0c0"
@janpipek
janpipek / plot_world_covid.py
Created March 11, 2020 18:45
Plot simple map with Prague and
from bokeh.plotting import figure, show, output_notebook
from bokeh.models import HoverTool
from bokeh.tile_providers import Vendors, get_provider
import pandas as pd
def web_mercator(long, lat):
import numpy as np
scale_x = 4e7 / 360
limit_lat = 2 * np.arctan(np.exp(np.pi)) - np.pi / 2
@janpipek
janpipek / gleamviz_data.py
Last active March 11, 2020 17:05
Gleamviz data reader
import os
from typing import List, Optional
import pandas
class DataReader:
def __init__(self, root_path: str):
self.root_path = root_path
@janpipek
janpipek / ukol_1.py
Last active October 22, 2020 09:35
opakovaci_ukoly
# 1. Spočítejte a nakreslete graf, jak se v průběhu let vyvíjel
# celkový počet udělených medailí (zvlášť pro zimní a letní hry).
import pandas as pd
import seaborn as sns
%matplotlib inline
olympics = pd.read_csv("athlete_events.csv")
@janpipek
janpipek / private_members.py
Created January 30, 2020 07:10
Private members in Python
class Jablko:
def __init__(self):
self.__bar = 123
@staticmethod
def show_me(o):
print(o.__bar)
class IgnorePrivateMembers:
def __getattr__(self, name: str):
@janpipek
janpipek / which.py
Last active January 26, 2020 02:59
How to implement `which` in pandas
import pandas as pd
def which(series):
# Error handling omitted
if not isinstance(series, pd.Series):
series = pd.Series(series)
return series[series.astype(bool) == True].index.tolist()
# Way to extend a Series
# See: https://pandas.pydata.org/pandas-docs/stable/development/extending.html#registering-custom-accessors
@janpipek
janpipek / kolacovy_graf.py
Created January 5, 2020 17:25
Koláčový graf
# TODO: Přesunout někam jinam :-)
import pandas as pd
kolac = pd.Series(
[1, 1, 1] * 2,
index = ["mák", "tvaroh", "povidla"] * 2
)
ax = kolac.plot.pie(
figsize=(8, 8),
title="Koláčový graf",
@janpipek
janpipek / benchmark.py
Last active October 2, 2019 10:59
Benchmark pyasn1
from statistics import mean, stdev
import timeit
import pyasn1
from pyasn1.codec.ber.decoder import decode as ber_decode
from pyasn1.codec.der.decoder import decode as der_decode
from pyasn1.type import namedtype
from pyasn1.type import univ
from pyasn1.compat.octets import ints2octs, str2octs, null
@janpipek
janpipek / hist3_with_slider.json
Created February 28, 2018 16:59
3D histogram in physt displayed as map with slider
{
"$schema": "https://vega.github.io/schema/vega/v3.json",
"width": 400,
"height": 200,
"padding": 5,
"title": {
"text": "3D normal distribution"
},
"scales": [
{