Created
September 17, 2013 21:12
-
-
Save davidandrzej/6600704 to your computer and use it in GitHub Desktop.
Subsample CSV rows in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import random | |
outf = open('output.csv','w') | |
writer = csv.writer(outf) | |
for row in csv.reader(open('input.csv', 'rb')): | |
if(random.randint(0,1) == 0): # eg, drop 50% | |
writer.writerow(row) | |
outf.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment