15 December 2014

Pandas Tutorials

read.table

snpibd = pd.read_table("largedata/IBD/allsnps_11m_IBD.bed", sep="\t", header= None)
gerp = pd.read_csv("largedata/SNP/allsnps_11m_gerpv2_tidy.csv")

replace = gsub

snpibd[3].replace("chr", "", regex=True, inplace=True)

paste

snpibd['snpid'] = snpibd[3].map(str) + "_" + snpibd[2].map(str)
snpibd['ibdid'] = snpibd[3].map(str) + "_" + snpibd[4].map(str)

merge

snp11mgp = pd.merge(gerp130m[["snpid", "N", "RS"]], snp11m, on='snpid', sort=False, how='right')

write.csv

snp11mgp.to_csv("largedata/SNP/allsnps_11m_gerpv2.csv", index=False)


blog comments powered by Disqus