Skip to content

Instantly share code, notes, and snippets.

@neil90
Created July 11, 2016 22:45
Show Gist options
  • Save neil90/0d05657275ae8c447ef5f34356469768 to your computer and use it in GitHub Desktop.
Save neil90/0d05657275ae8c447ef5f34356469768 to your computer and use it in GitHub Desktop.
from faker import Faker
import datetime
import random
import sys
import csv
fake = Faker()
outfile = 'data_test.csv'
outsize = 1024 * 3024
data = []
#Create people
for i in range(15):
name = fake.name()
age = fake.random_int(min=18, max=99)
address = fake.address().replace('\n',' ')
salary = fake.random_int(min=50000, max=250000)
data.append((name, age, address, salary))
with open(outfile, 'w', newline='') as csvfile:
#Creates lists for combination for random data
amount_list = [random.randint(1,50) for i in range(30)]
qty_list = [i for i in range(15)]
purchase_date_list = [datetime.date(random.randint(2005,2015),
random.randint(1,12),
random.randint(1,28)).strftime('%Y-%m-%d')
for i in range(10000)]
product_list = [
'water', 'beer', 'chips', 'chocolate',
'pretzels', 'wine', 'fish', 'steak'
]
size = 0
csvwriter = csv.writer(csvfile)
while csvfile.tell() < outsize:
profile = random.choice(data)
product = random.choice(product_list)
amount = random.choice(amount_list)
qty = random.choice(qty_list)
purchase_date = random.choice(purchase_date_list)
row = [
profile[0], profile[1],
profile[2], profile[3],
product, amount, qty,
purchase_date
]
csvwriter.writerow(row)
p = float(csvfile.tell()) / outsize
status = r"{0} [{1:.2%}]".format(csvfile.tell(), p)
status = status + chr(8)*(len(status)+1)
sys.stdout.write(status)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment