Member-only story
Using Python & Faker to Make Start & End Times
Do you ever run into situations where you need a data set, but it doesn’t exist?
Maybe your PM is incredibly impatient, and you are being asked to build a dashboard before the database is ready. Maybe you are testing your friend’s code but you don’t have access to their database. Maybe there is another reason. It doesn’t matter. Sometimes you need data that meets certain criteria, and it just doesn’t exist.
There’s a really cool package for Python that can do this. It’s called Faker.
If you search around, there are plenty of available examples of how to use Faker. But I haven’t been able to find any that explain how to make 2 dates, where 1 is after the other. So, I figured it out.
For now, rather than provide a lengthy explanation of what is happening, I’m going to take a Stack Overflow like approach to this, and just paste the code here. The example code is based on a real life experience I had, and it illustrates a few of the common things you might want to use Faker for.
The comments should be enough to get you on the right path:
from faker import Faker
import random
from datetime import timedelta
import pandas as pd
# Create a Faker instance
fake = Faker()
# Define some of the attribute values
agent_names = ['Agent A', 'Agent B'…