Skip to content

Instantly share code, notes, and snippets.

View govorunov's full-sized avatar

Yaroslav Govorunov govorunov

View GitHub Profile
import numpy as np
def np_z_trim(x, threshold=10, axis=0):
""" Replace outliers in numpy ndarray along axis with min or max values
within the threshold along this axis, whichever is closer."""
mean = np.mean(x, axis=axis, keepdims=True)
std = np.std(x, axis=axis, keepdims=True)
masked = np.where(np.abs(x - mean) < threshold * std, x, np.nan)
min = np.nanmin(masked, axis=axis, keepdims=True)
@govorunov
govorunov / parallel_apply.py
Last active June 15, 2023 20:44
Parallelize Pandas apply over multiple workers using Joblib.
from joblib import Parallel, delayed, effective_n_jobs
import pandas as pd
def gen_even_slices(n, n_packs, *, n_samples=None):
"""Generator to create n_packs slices going up to n.
Parameters
----------
n : int
n_packs : int
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/bin/bash
# Calculate lines of code in all *.py files excepting folders containig 'site-packages' in names
cat `find -name '*.py' ! -path '*site-packages*'` | wc -l -
@govorunov
govorunov / django_list_field.py
Created November 20, 2018 00:49
A custom Django model field to represent Python lists as comma separated strings in database
from django.db import models
from typing import Iterable
class ListField(models.TextField):
"""
A custom Django field to represent lists as comma separated strings
"""
def __init__(self, *args, **kwargs):
self.token = kwargs.pop('token', ',')
#!/usr/bin/env python2
"""
Solar Analytics code assignment
"""
from __future__ import print_function
__author__ = "Yaroslav Hovorunov"
__version__ = "0.1.0"
__license__ = "MIT"
@govorunov
govorunov / max_prod_subsequence.ipynb
Last active October 4, 2018 09:44
Find subsequence with max product
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.