Skip to content

Instantly share code, notes, and snippets.

View andilabs's full-sized avatar
👨‍💻
still in love with coding!

Andrzej Kostanski andilabs

👨‍💻
still in love with coding!
View GitHub Profile
@andilabs
andilabs / gist:6547414
Created September 13, 2013 06:51
analysis
from numpy import arange
from scipy import stats
l=arange(0.1,1,0.1)
print l
import itertools as it
pr=it.product(l,repeat=6)
l2=list()
for i in pr:
l2.append(i)
@andilabs
andilabs / gist:6571955
Created September 15, 2013 15:54
10c experiment subset
from numpy import arange
from scipy import stats
l=arange(0.25,1.01,0.25)# l=arange(0.1,1,0.1)
print l
import itertools as it
pr=it.product(l,repeat=6)
l2=list(pr)
# for i in pr:
# l2.append(i)
@andilabs
andilabs / gist:6586488
Created September 16, 2013 20:56
Create CSVs from all spreadsheets in Excel's workbook
# -*- coding: utf-8 -*-
import xlrd
import csv
from os import sys
def csv_from_excel(excel_file):
workbook = xlrd.open_workbook(excel_file)
all_worksheets = workbook.sheet_names()
for worksheet_name in all_worksheets:
worksheet = workbook.sheet_by_name(worksheet_name)
@andilabs
andilabs / gist:6589261
Last active December 23, 2015 05:49
wojtekw - z poprawnym przeskalowaniem
library(matrixStats)
library(R.methodsS3)
#biblioteki plyr uzyjemy do szybkiego wygenerowania podsumowan
library(plyr)
#do wykresow:
require(ggplot2)
#wyczyść wszystkie zmienne z pamięci
rm(list=ls(all=TRUE))
@andilabs
andilabs / gist:6589644
Created September 17, 2013 03:10
dictionary in R
You do not even need lists if your "number" values are all of the same mode. If I take Dirk Eddelbuettel's example:
> foo <- c(12, 22, 33)
> names(foo) <- c("tic", "tac", "toe")
> foo
tic tac toe
12 22 33
> names(foo)
[1] "tic" "tac" "toe"
Lists are only required if your values are either of mixed mode (for example characters and numbers) or vectors.
@andilabs
andilabs / gist:6610922
Created September 18, 2013 15:30
concatenating 2 text columns in a data.frame
> dat=read.csv(file.choose(),header=FALSE,sep=" ")
> head(dat)
V1 V2 V3 V4
1 83965 891552 Identifiable People
2 88599 891552 Identifiable People
3 42966 891552 Identifiable People
4 83965 891553 Unidentifiable People
5 88599 891553 Unidentifiable People
6 42966 891553 Unidentifiable People
> dat$LABEL<-do.call(paste,c(dat[c("V3","V4")],sep="_"))
@andilabs
andilabs / gist:6610969
Created September 18, 2013 15:32
Remove given columns from data frame
dat<-dat[,!(names(dat) %in% c("V3","V4"))]
@andilabs
andilabs / gist:6621149
Last active December 23, 2015 10:19
Pivoting data from MTURK to the format of MACE
import csv
from sets import Set
import sys
results = {}
items = Set()#[]
workers = Set()#[]
def addItem(idict):
#appending sets of workers and items
if int(idict['worker']) not in workers:
workers.add(int(idict['worker']))
@andilabs
andilabs / gist:6621716
Last active December 23, 2015 10:29
BASH replace all '\t' with '\n'
tr '\t' '\n' <input >output
@andilabs
andilabs / gist:6621741
Created September 19, 2013 10:44
Reshape golds for MACE
import csv
from sets import Set
import sys
golds = {}
items = Set()
def loadData(path):
with open(path,'rU') as F:
csvdr = csv.DictReader(F,delimiter='\t')
for p in csvdr:
items.add(int(p['item']))