Created
August 31, 2018 09:04
-
-
Save chinying/25a720b68582c328126b03eaa31ee273 to your computer and use it in GitHub Desktop.
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 | |
def randTime(size=500): | |
timings = [700, 730, 800, 830, 900] | |
return (random.choices(timings, k=size)) | |
def generate(contents, size=500): | |
r = [contents[(random.randint(0, len(contents)))] | |
for i in range(size * 2)] | |
origins = random.choices() | |
r = list(map(lambda x: x[0], r)) # postal code is in first column of csv dump | |
randomTimes = randTime(size) | |
rows = [] | |
rows.append("Index,Origin,Destination,Time") | |
for i in range(size): | |
rows.append("{},{},{},{}".format(i, r[i], r[size+i], randomTimes[i])) | |
return rows | |
if __name__ == "__main__": | |
infile = "./postal_code_to_address.csv" | |
with open(infile) as csvfile: | |
csvreader = csv.reader(csvfile, delimiter=',', quotechar='"') | |
next(csvreader) | |
contents = list(csvreader) | |
csvfile.close() | |
with open("cf-file.csv", 'w') as outfile: | |
outfile.write("\n".join(generate(contents, 500))) | |
outfile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment