Skip to content

Instantly share code, notes, and snippets.

@tcovert
Created August 20, 2015 19:43
Show Gist options
  • Save tcovert/7310d9ad79c1b46d0fe0 to your computer and use it in GitHub Desktop.
Save tcovert/7310d9ad79c1b46d0fe0 to your computer and use it in GitHub Desktop.
DataFrames.jl non-working unstack() example
using DataFrames
ids = rand(15000:25000, 1600)
ids = unique(ids)
ids = String[string("f",x) for x in ids]
keys = 1:200
keys = String[string("k",x) for x in keys]
temp = join(DataFrame(id = ids), DataFrame(key = keys), kind = :cross)
keepflag = rand(size(temp,1))
keepflag = keepflag .> .8
temp = temp[keepflag, :]
temp[:v] = 1
temp2 = unstack(temp, :key, :v)
temp3 = unstack(temp, :id, :key, :v)
s0 = size(unique(ids))
s1 = size(unique(temp[:id]))
s2 = size(unique(temp2[:id]))
s3 = size(unique(temp3[:key]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment