Created
February 26, 2019 21:46
-
-
Save javierwilson/6b3ec9f714e881fc98a7f35d0096d506 to your computer and use it in GitHub Desktop.
Create Fake CSV data
This file contains hidden or 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
#!/usr/bin/python | |
import csv | |
import copy | |
import random | |
def play(datum, min=1, max=25): | |
if datum == '': | |
return 0 | |
else: | |
return int(datum) + int((random.randint(min, max)/100.0) * int(datum)) | |
with open('Forms-Geo.csv','r') as csvinput: | |
with open('Forms-Geo-Fake.csv', 'w') as csvoutput: | |
writer = csv.writer(csvoutput, lineterminator='\n') | |
reader = csv.reader(csvinput) | |
all = [] | |
# adds 'Year' columns | |
row = next(reader) | |
row.append('Year') | |
all.append(row) | |
original = list(reader) | |
# adds '2019' for all rows | |
current = copy.deepcopy(original) | |
for row in current: | |
row.append(2019) | |
all.append(row) | |
# copies the whole thing to 2020 | |
current = copy.deepcopy(original) | |
for row in current: | |
row.append(2020) | |
row[45] = play(row[45]) | |
all.append(row) | |
# copies the whole thing to 2021 | |
current = copy.deepcopy(original) | |
for row in current: | |
row.append(2021) | |
row[45] = play(row[45], 25, 50) | |
all.append(row) | |
writer.writerows(all) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment