Skip to content

Instantly share code, notes, and snippets.

View szeitlin's full-sized avatar

Sam Zeitlin szeitlin

View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@szeitlin
szeitlin / pyladies_practice_geojson
Created February 12, 2014 01:59
example from Lynn Root's workshop.
import geojson
import parse as p #shorter name for our parse program
def create_map(data_file):
"""csv file -> parse -> creates a geojson - javascript object notation - file """
# define the type of geoJSON that we're creating
geo_map = {"type": "FeatureCollection"} #GeoJSON specification
@szeitlin
szeitlin / pyladies_import_csv_long_way
Created February 12, 2014 02:01
example from Lynn Root's workshop.
import csv
MY_FILE = "../data/sample_sfpd_incident_all.csv"
#../ means go up one directory
#all caps means a constant variable
def parse(raw_file, delimiter):
""" csv file -> JSON-like object"""
@szeitlin
szeitlin / pyladies_practice_parsing
Created February 12, 2014 02:36
example from Lynn Root's workshop.
from collections import Counter #collections is a standard library, Counter is capitalized
import csv
import matplotlib.pyplot as plt #renames the pyplot function from third party library
import numpy.numarray as na # best practices: import in alphabetical order
MY_FILE = "../data/sample_sfpd_incident_all.csv"
def parse(raw_file, delimiter):
""" csv file -> JSON-like object"""
@szeitlin
szeitlin / ACTG_count.py
Created February 12, 2014 02:48
Rosalind problem 1 solution.
#Rosalind problem 1
def ACGT_count(sequence):
'''
(str) -> (int, int, int, int)
Count the number of A, C, G and T in a string.
>>>ACGT_count('ATGCTTCAGAAAGGTCTTACG')
6 4 5 1
@szeitlin
szeitlin / transcribe
Created February 12, 2014 02:50
Rosalind problem: convert DNA sequence to RNA.
def transcribe(s):
'''given a DNA string, replace each T with a U and write it back out as RNA
(str) -> (str)
>>>transcribe('ATGCCCGGGTTTAAA')
AUGCCCGGGUUUAAA
'''
@szeitlin
szeitlin / complementary
Created February 12, 2014 02:51
Rosalind problem: reverse complement strand.
def complementary(s):
'''
(str) -> (str)
Returns the reverse complementary strand of s.
>>>complementary('AAACCCTTTGGG')
CCCAAAGGGTTT
'''
@szeitlin
szeitlin / fizzbuzz.py
Created February 25, 2014 22:31
fizzbuzz
def fizzbuzz(last):
list = range(1, (last + 1))
for num in list:
if num % 15 == 0:
num = "fizzbuzz"
print str(num)
elif num % 3 == 0:
num = "fizz"
@szeitlin
szeitlin / summarize_vincent.py
Created March 25, 2014 18:28
practicing taking data semi-blindly, importing & filtering via pandas, viewing with vincent.
__author__= 'szeitlin'
import pandas
import vincent
MYFILE = "UNdata_Export_20140325_115007094.csv"
#read in a csv file
mydata = pandas.read_csv(MYFILE)
__author__ = 'szeitlin'
def return_duplicates(nums):
"""
(list) -> (sub-list)
look for duplicates and just return those
>>> return_duplicates([5,5,2,3,4,5,2])
[2, 2, 5, 5, 5]