Skip to content

Instantly share code, notes, and snippets.

View dutc's full-sized avatar

James Powell dutc

View GitHub Profile
@dutc
dutc / groupby.aggregate.py
Last active July 13, 2021 16:16
“Python Expert” Newsletter (July 21, 2021): Learning Corner
from numpy import tile, repeat
from numpy.random import default_rng
from pandas import DataFrame, date_range, Timestamp
from pandas.tseries.offsets import Day
from random import seed
from scipy.stats import zscore
from string import ascii_lowercase
if __name__ == '__main__':
rng = default_rng(s := Timestamp('2021-07-04').asm8.astype('uint32'))
@dutc
dutc / groupby.transform.py
Created July 13, 2021 16:15
“Python Expert” Newsletter (July 14, 2021): Learning Corner
from numpy import tile, repeat
from numpy.random import default_rng
from pandas import DataFrame, date_range, Timestamp
from pandas.tseries.offsets import Day
from random import seed
from scipy.stats import zscore
from string import ascii_lowercase
if __name__ == '__main__':
rng = default_rng(s := Timestamp('2021-07-04').asm8.astype('uint32'))
@dutc
dutc / groupby.py
Created July 7, 2021 15:56
“Python Expert” Newsletter (July 7, 2021): Learning Corner
#!/usr/bin/env python3
from functools import total_ordering
from dataclasses import dataclass
from numpy import tile, repeat
from numpy.random import default_rng
from pandas import DataFrame, date_range, Timestamp
from pandas.core.dtypes.common import is_numeric_dtype
from random import seed
from string import ascii_lowercase
@dutc
dutc / slides.clay
Created April 7, 2021 20:03
“Python Expert” Newsletter (Apr 4, 2021): Slides for “What Does it All Really Mean?” (https://www.youtube.com/watch?v=hYi9S0GwVB8)
! pulse
What Does It All
<i>Really</i> <b>Mean</b> <i>?</i>
! fade
What Does It All
<i>Really</i> <b>Mean</b> <i>?</i>
\
☆ PyCon India ☆ Sat Oct 3, 2020 ☆
@dutc
dutc / cidict.py
Created March 24, 2021 23:35
“Python Expert” Newsletter (Mar 23, 2021): Learning Corner, Python Data Structure Fundamentals and “Concordance”
from collections.abc import Mapping, MutableMapping
class cidict(dict):
''' a case insensitive, immutable `dict` subclass '''
def __init__(self, *args, **kwargs):
super().__init__({k.lower(): v for k, v in dict(*args, **kwargs).items()})
def __missing__(self, key):
return self[key.lower()]
__setitem__ = __delitem__ = None
clear = update = pop = popitem = setdefault = update = None
@dutc
dutc / cities15000.txt
Created March 9, 2021 04:51
`wmeet`: “when do I meet, timezone-aware!”
This file has been truncated, but you can view the full file.
3040051 les Escaldes les Escaldes Ehskal'des-Ehndzhordani,Escaldes,Escaldes-Engordany,Les Escaldes,esukarudesu=engorudani jiao qu,lai sai si ka er de-en ge er da,Эскальдес-Энджордани,エスカルデス=エンゴルダニ教区,萊塞斯卡爾德-恩戈爾達,萊塞斯卡爾德-恩戈爾達 42.50729 1.53414 P PPLA AD 08 15853 1033 Europe/Andorra 2008-10-15
3041563 Andorra la Vella Andorra la Vella ALV,Ando-la-Vyey,Andora,Andora la Vela,Andora la Velja,Andora lja Vehl'ja,Andoro Malnova,Andorra,Andorra Tuan,Andorra a Vella,Andorra la Biella,Andorra la Vella,Andorra la Vielha,Andorra-a-Velha,Andorra-la-Vel'ja,Andorra-la-Vielye,Andorre-la-Vieille,Andò-la-Vyèy,Andòrra la Vièlha,an dao er cheng,andolalabeya,andwra la fyla,Ανδόρρα,Андора ла Веля,Андора ла Веља,Андора ля Вэлья,Андорра-ла-Велья,אנדורה לה וולה,أندورا لا فيلا,አንዶራ ላ ቬላ,アンドラ・ラ・ヴェリャ,安道爾城,안도라라베야 42.50779 1.52109 P PPLC AD 07 20430 1037 Europe/Andorra 2010-05-30
290594 Umm al Qaywayn Umm al Qaywayn Oumm al Qaiwain,Oumm al Qaïwaïn,Um al Kawain,Um al Quweim,Umm al Qaiwain,Umm al Qawain,Umm al Qaywayn,Umm al-Quwain,Um
@dutc
dutc / original-solution.py
Last active March 8, 2021 15:33
“Python Expert” Newsletter (Mar 3, 2021): Learning Corner, Python Data Structure Fundamentals and “Concordance”
# original attendee solution, PRIOR to refactoring
text = '''
I'm not your friend or anything,
You think that you're the man
I think, therefore, I am
I'm not your friend or anything,
You think that you're the man
I think, therefore, I am
@dutc
dutc / 1.py
Created March 3, 2021 02:50
`pandas` problem of the day: analysis (with `numpy.meshgrid`‽)
from pandas import Series
s = Series({
4: 89.00,
6: 109.99,
8: 149.14,
10: 218.99,
12: 239.09,
14: 279.99,
16: 329.99,
18: 409.99,
@dutc
dutc / example.py
Created February 19, 2021 16:48
Simple example of `pandas.Series.apply` vs `pandas.Series.groupby.apply` performance
#!/usr/bin/env python3
from pandas import Series
from numpy import repeat
from numpy.random import choice
from string import ascii_lowercase
from time import perf_counter, sleep
from contextlib import contextmanager
@contextmanager
@dutc
dutc / example.py
Created February 19, 2021 16:33
Simple example of `numpy` vs Pure Python
#!/usr/bin/env python
from random import randint as python_randint
from numpy.random import randint as numpy_randint
from numpy import dot as numpy_dot
from time import perf_counter
from collections import namedtuple
from itertools import islice, tee
from contextlib import contextmanager