This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Most of the time, it’s pretty easy to take a Pandas data frame that contains | |
timestamps and plot it, for example using `df.plot(…)`. Nowadays many of | |
high-level Matplotlib functions are canny enough to handle Pandas timestamps on | |
their own as well. | |
But not all of them. | |
So how do you get nice handling of Pandas timestamps when you need to use | |
Matplotlib directly? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Problem: provide two-way communication with a subprocess in Python. | |
See also: | |
- https://kevinmccarthy.org/2016/07/25/streaming-subprocess-stdin-and-stdout-with-asyncio-in-python/ | |
- http://eli.thegreenplace.net/2017/interacting-with-a-long-running-child-process-in-python/ | |
""" | |
import asyncio | |
import sys |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See also https://github.com/minrk/findspark | |
import os | |
from pathlib import Path | |
import sys | |
def configure_spark(spark_home: str = None, python_path: str = None): | |
if not spark_home: | |
spark_home = os.environ['SPARK_HOME'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
def describe_population(df: pd.DataFrame) -> pd.DataFrame: | |
""" | |
Report the populated and uniqueness counts for each column of the input. | |
The ratio columns are given as percents. | |
""" | |
N = len(df) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def extent(collection): | |
""" | |
Return the minimum and maximum values from an iterable in one pass | |
""" | |
itr = iter(collection) | |
first_value = next(itr) | |
minimum = first_value | |
maximum = first_value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from operator import ( | |
from cytoolz.curried.operator import ( | |
add, | |
and_, | |
attrgetter, | |
# concat, | |
contains, | |
countOf, | |
delitem, | |
eq, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function abspath() { | |
# generate absolute path from relative path | |
# $1 : relative filename | |
# return : absolute path | |
# From http://stackoverflow.com/a/23002317/514210 | |
if [[ -d "$1" ]]; then | |
# dir | |
(cd "$1"; pwd) | |
elif [[ -f "$1" ]]; then | |
# file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Automatically hide the toolbar and header in Jupyter Notebook 4.1.0 | |
// This should go in ~/.jupyter/custom/custom.js | |
require( | |
['base/js/namespace', 'base/js/events'], | |
function(Jupyter, events) { | |
events.on("notebook_loaded.Notebook", function () { | |
Jupyter.toolbar.actions.call('jupyter-notebook:toggle-toolbar') | |
Jupyter.toolbar.actions.call('jupyter-notebook:toggle-header') | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% \labeledrule[width]{Top}{Bottom} | |
% | |
% Useful for creating forms. The text above the rule is aligned to the | |
% surrounding baseline. A zero-width box contains the top label. The second | |
% command takes the bottom label and lowers it by \baselineskip, then packs it | |
% into a box with width zero, height of 1 em, and depth of \baselineskip plus | |
% the depth of the bottom label text. The height of the rule (0.4pt) is TeX's | |
% hard-coded height for \hrule. | |
\newcommand{\labeledrule}[3][\linewidth]{% |
NewerOlder