Skip to content

Instantly share code, notes, and snippets.

View cottrell's full-sized avatar
💭
whooosh

David Cottrell cottrell

💭
whooosh
View GitHub Profile
def monkey_patch_pandas():
import pandas as pd
import functools
@functools.wraps(pd.Series.str.contains)
def _grep(self, *args, **kwargs):
if not hasattr(self, '_greppable'):
self._greppable = pd.Series(self.to_csv().split('\n')[1:-1])
i = self._greppable.str.contains(*args, **kwargs)
return self.iloc[i.values]
pd.DataFrame.grep = _grep
@cottrell
cottrell / discussion.py
Last active October 3, 2023 10:02
Equinox module state extraction and serialization
import dataclasses
import importlib
# begin serialization lib
import io
import json
import lzma
import pickle
from base64 import b64decode, b64encode
from types import FunctionType