Skip to content

Instantly share code, notes, and snippets.

View vegarsti's full-sized avatar

Vegard Stikbakke vegarsti

View GitHub Profile

pandoc file.md -o file.pdf

  • To count occurrences when aggregating (e.g. in pivot_table), use len as aggfunc!

  • To drop a row: Cheatsheet

    • df[df.name != 'Tina']
    • df.drop(df.index[2])
  • c['a'].shift(periods=1)

@vegarsti
vegarsti / jupyter-notify.md
Created September 13, 2017 08:22
Jupyter notebook: Get notified when cell is done
# defaultdict use case
# Finding a Pareto front, where (x1, x2) is a list of tuples satisfying
# e.g. (x1, x2) : |df[(df[var1 > x1]) & df[var2 > x2)]| < 0.1|df|,
# where |df| is the size of df, i.e., df.shape[0] (in Pandas)
pareto = defaultdict(lambda: np.Inf)
for x1, x2 in xs:
pareto[x1] = min(pareto[x1], x2)
  • Virtualenv & stuff (incl. autoenv): Read!
  • Homebrew
  • LaTeX w/ Sublime

Requires node.js and npm.

First, do npm install -g ijavascript. Then run ijs once.

@vegarsti
vegarsti / tree.md
Created April 25, 2017 12:12 — forked from hrldcpr/tree.md
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

  • plt.savefig(filename, bbox_inches='tight') --> get the entire plot when saved
  • Reset to factory default matplotlib style
import matplotlib as mpl
mpl.rcParams.update(mpl.rcParamsDefault)
  • plt.axes('tight') removes all space around the area of the curve
  • plt.axes('equal') ensures x-y even
  • plt.axhline(y=production_accuracy, linewidth=2, color='k', label='production') horizontal line
  • save: C-x C-s (+ enter)
  • open file: C-x C-f
  • switch to buffer: C-x b
  • meta key M is escape and left alt (option)
  • C-k: kills from cursor until end of line
  • C-/ (7) -- undo!
  • C-a start of line
  • C-e start of line
  • M-f forward one word
  • M-b back one word
  • plot(x, y) + abline(a, b, col="red", lwd=2)
  • plot(x, y, type="b", col="red", pch=19) "dotdash" med filled
  • plot(x, y, type="b", col="red") "dotdash" uten filled
  • rm(list=ls(all=TRUE)) remove stuff
  • `sapply(.., simplify='array') == unlist(lapply(..))