Skip to content

Instantly share code, notes, and snippets.

Taro Kuriyama tkuriyama

Block or report user

Report or block tkuriyama

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View useful_pandas_snippets.md

Useful Pandas Snippets

A personal diary of DataFrame munging over the years.

Data Types and Conversion

Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)

@tkuriyama
tkuriyama / .vimrc
Last active May 23, 2017
vim config
View .vimrc
""" Plugins https://github.com/tpope/vim-pathogen
execute pathogen#infect()
""" General UI
" line numbers
set number
" Turn on the WiLd menu
@tkuriyama
tkuriyama / fording_puzzle_v3.py
Last active Jun 18, 2016
River Fording Puzzle v3
View fording_puzzle_v3.py
"""River Fording Puzzle.
3 girls, each with her father, go for a stroll. They come to a small river.
One boat, able to carry 2 persons at a time, is at their disposal.
Crossing would be simple for everyone except the girls. None is willing to be
in the boat or ashore with 1 or 2 strange fathers, unless her own father is
present too. How do they all get across?
"""
@tkuriyama
tkuriyama / fording_puzzle_v2.py
Created Jun 18, 2016
River Fording Puzzle v2
View fording_puzzle_v2.py
"""River Fording Puzzle.
3 girls, each with her father, go for a stroll. They come to a small river.
One boat, able to carry 2 persons at a time, is at their disposal.
Crossing would be simple for everyone except the girls. None is willing to be
in the boat or ashore with 1 or 2 strange fathers, unless her own father is
present too. How do they all get across?
"""
@tkuriyama
tkuriyama / fording_puzzle_v1.py
Created Jun 18, 2016
River Fording Puzzle v1
View fording_puzzle_v1.py
"""River Fording Puzzle.
3 girls, each with her father, go for a stroll. They come to a small river.
One boat, able to carry 2 persons at a time, is at their disposal.
Crossing would be simple for everyone except the girls. None is willing to be
in the boat or ashore with 1 or 2 strange fathers, unless her own father is
present too. How do they all get across?
"""
@tkuriyama
tkuriyama / lex_perm.py
Last active Dec 23, 2015
Find lexicographical predecessor or successor (permutation)
View lex_perm.py
import sys
### Test
def test_predecessor():
"""Basic unit tests for find_predecessor."""
assert main('1432', 0) == '1423'
assert main('04123', 0) == '03421'
assert main('315426', 0) == '315264'
assert main('315246', 0) == '314652'
@tkuriyama
tkuriyama / fold_syntax_tests
Last active Sep 27, 2015
Testing GitHub syntax highlighting in F#
View fold_syntax_tests
let product = List.fold (*) 1
let product = List.fold (fun acc x -> acc * x) 1
let fold1 f items =
List.fold f (List.head items) (List.tail items)
@tkuriyama
tkuriyama / weighted_draw.py
Last active Sep 19, 2015
Probability-weighted drawing.
View weighted_draw.py
from __future__ import division
import random
def weighted_draw(items, target):
"""Draw item from iterable based on probability distribution of items.
Args
items: tuple of (item: float of probability) pairs where the.
sum probability has been normalized to 1
target: float, random number between 0 and 1 used to determine
the item to draw from items
@tkuriyama
tkuriyama / blacksmith.py
Last active Sep 19, 2015
Solver for "Blacksmith Khecho's Ingenuity"
View blacksmith.py
"""Blacksmith Khecho's Ingenuity
[...]
Khecho, calmly looking around, climbed the steps to the tower's upper
part and glanced out the window. He realized it would be impossible to
jump out and survive. But he saw a rope, forgotten by the masons, hanging
near the window. The rope was thrown over a rusty tackle fastned to the
tower wall above the window. Empty baskets were tied to each end of the
rope. Those baskets had been used by the masons to lift bricks and lower
@tkuriyama
tkuriyama / jumping_checkers.py
Created Aug 16, 2015
Solver for "Jumping Checkers" puzzle.
View jumping_checkers.py
"""Solver for "Jumping Checkers" problem.
Place 3 white checkers in squares 1, 2, and 3 of the figure, and 3 black ones
on swuares 5, 6, 7. Shift the white checkers to the squares occupied by the
black ones, and vice versa.
Board |0|0|0| |1|1|1|
Square # 1 2 3 4 5 6 7
You may move a checker forward to an adjacent unoccupied square, if any.
You can’t perform that action at this time.