Skip to content

Instantly share code, notes, and snippets.

@akamor
Created April 8, 2019 22:58
Show Gist options
  • Save akamor/cb0c6acc0f57d6646cb57585d7b4299b to your computer and use it in GitHub Desktop.
Save akamor/cb0c6acc0f57d6646cb57585d7b4299b to your computer and use it in GitHub Desktop.
import random
from datetime import timedelta, datetime
from faker import Faker
from faker.providers import person
from faker.providers import internet
from faker.providers import ssn
from faker.providers import address
from faker.providers import job
from faker.providers import date_time
fake = Faker()
fake.add_provider(person)
fake.add_provider(internet)
fake.add_provider(ssn)
fake.add_provider(address)
fake.add_provider(job)
fake.add_provider(date_time)
numRows = 10
d = dict()
d['first_name'] = lambda: fake.first_name()
d['last_name'] = lambda: fake.last_name()
d['gender'] = lambda: 'M' if random.randint(0,1) == 0 else 'F'
d['personal_email'] = lambda: fake.email()
d['ssn'] = lambda: fake.ssn()
#Note that on windows you cannot currently use the date_time functionality in Faker due to a known bug. Comment out the following two lines and uncomment the two lines below that.
#d['birth_date'] = lambda: fake.date_between_dates(date_start=datetime(1960, 1, 1), date_end=datetime(2000, 1, 1))
#d['start_date'] = lambda: fake.date_between_dates(date_start=datetime(1995, 1, 1), date_end=datetime(2019, 1, 1))
d['birth_date'] = lambda: (datetime(1960, 1, 1) + timedelta(seconds=1261600000)).strftime('%m/%d/%Y')
d['start_date'] = lambda: (datetime(1995, 1, 1) + timedelta(seconds=725420000)).strftime('%m/%d/%Y')
d['office'] = lambda: fake.city()
d['title'] = lambda: fake.job()
d['org'] = lambda: random.choice(['Engineer','Sales','Associate','Manager','VP'])
d['accrued_holidays'] = lambda: random.randint(0,20)
d['salary'] = lambda: round(random.randint(90000,120000)/1000)*1000
d['bonus'] = lambda: round(random.randint(0,5000)/500)*500
for _ in range(numRows):
print([d[k]() for k in d.keys()])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment