Skip to content

Instantly share code, notes, and snippets.

View drorata's full-sized avatar

Dror Atariah drorata

View GitHub Profile
@drorata
drorata / nests_group_by_counts_ratio.ipynb
Created July 10, 2017 09:12
Nested groups counting and ratio
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@drorata
drorata / notebook.sh
Created July 14, 2017 12:15
Wrapper to start Jupyter notebook with tweaked path
#!/usr/bin/env bash
echo "Saving PYTHONPATH"
ORIGINAL_PYTHONPATH=$PYTHONPATH
echo "Prepending package to PYTHONPATH"
export PYTHONPATH="$PWD/:$PWD/mypackage/::$ORIGINAL_PYTHONPATH"
echo "Starting Jupyter"
jupyter notebook
echo "Reverting to the original PYTHONPATH"
export PYTHONPATH=$ORIGINAL_PYTHONPATH
@drorata
drorata / predict_row.py
Created July 24, 2017 06:54
Small utility that predicts the class of an instance (one row) from a pandas.DataFrame
def predict_row(row, clf):
"""
Transform row to a 1-row pandas.DataFrame and predict
When iterating of rows of a DataFrame, each row is represented as a
pd.Series. The classifiers in use are expecting a DataFrame. This function
turns the row into a 1 x n_featurs DataFrame and apply the prediction of a
trained classier.
Parameters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@drorata
drorata / gridsearch_cv_score.py
Created July 25, 2017 11:44
Minimal example of using
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.4)
parameters = {
'clf__C': [0.01, 0.1, 1, 2, 5, 10, 50, 100],
'clf__class_weight': [
{0: 1, 1: 1},
{0: 2, 1: 1}, {0:1, 1:2},
{0: 5, 1: 1}, {0:1, 1:5}]
}
@drorata
drorata / rows_per_time_unit.md
Created August 3, 2017 09:22
Rows per time unit using pandas

Assume you have a DataFrame as below:

import pandas as pd
import numpy as np

np.random.seed(42)
N = 10
df = pd.DataFrame(
 {
@drorata
drorata / Widgets_example.ipynb
Created September 1, 2017 08:14
A minimal example of using widgets in Jupyter notebook
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@drorata
drorata / Dockerfile
Created September 1, 2017 14:48
Install pymssql in a Docker contrainer
FROM continuumio/miniconda3
COPY environment.yml /tmp
RUN apt-get update && apt-get install -y \
freetds-dev \
python-dev \
build-essential \
&& rm -rf /var/lib/apt/lists/*
@drorata
drorata / example.ipynb
Last active December 23, 2025 02:19
Plotting all dates in the index of a DataFrame
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@drorata
drorata / send_email.py
Created September 27, 2017 13:45
Minimal example of sending a JSON over email
import json
# Import smtplib for the actual sending function
import smtplib
# Import the email modules we'll need
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from datetime import datetime
def send_email(data):