A personal diary of DataFrame munging over the years.
Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)
from flask import Flask, request, redirect, url_for, make_response, abort | |
from werkzeug import secure_filename | |
from pymongo import Connection | |
from pymongo.objectid import ObjectId | |
from gridfs import GridFS | |
from gridfs.errors import NoFile | |
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif']) | |
DB = Connection().gridfs_server_test | |
FS = GridFS(DB) |
import numpy as np | |
import matplotlib.pyplot as plt | |
from matplotlib import mlab | |
def one_over_f(f, knee, alpha): | |
desc = np.ones_like(f) | |
desc[f<KNEE] = np.abs((f[f<KNEE]/KNEE)**(-alpha)) | |
desc[0] = 1 | |
return desc |
#!/bin/bash | |
rotation=`xrandr --query --verbose | grep "LVDS1" | awk '{print $5}'` | |
if [ $rotation = "normal" ] | |
then | |
xsetwacom set "Serial Wacom Tablet stylus" Rotate half | |
xrandr -o inverted | |
else | |
xsetwacom set "Serial Wacom Tablet stylus" Rotate none | |
xrandr -o normal |
import numpy | |
import pylab | |
delta = 0.01 | |
omega = 0.05 | |
omega_noise = 0.2 | |
A = 5 | |
A_noise = 0.2 | |
phi = 0.8 | |
N = 1000 |
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
#include <iterator> | |
#include <assert.h> | |
typedef std::chrono::high_resolution_clock Clock; | |
template<typename T> |
A personal diary of DataFrame munging over the years.
Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)
#' When plotting multiple data series that share a common x axis but different y axes, | |
#' we can just plot each graph separately. This suffers from the drawback that the shared axis will typically | |
#' not align across graphs due to different plot margins. | |
#' One easy solution is to reshape2::melt() the data and use ggplot2's facet_grid() mapping. However, there is | |
#' no way to label individual y axes. | |
#' facet_grid() and facet_wrap() were designed to plot small multiples, where both x- and y-axis ranges are | |
#' shared acros all plots in the facetting. While the facet_ calls allow us to use different scales with | |
#' the \code{scales = "free"} argument, they should not be used this way. | |
#' A more robust approach is to the grid package grid.draw(), rbind() and ggplotGrob() to create a grid of | |
#' individual plots where the plot axes are properly aligned within the grid. |
#!/usr/bin/env python | |
from __future__ import print_function | |
import sys | |
import os | |
import glob | |
import shutil | |
import sqlite3 | |
from os.path import join as joinpath, expanduser, exists, isabs, realpath |