Created
September 3, 2021 10:09
-
-
Save bbelderbos/63326c81cfd439619ac30cfd3c351747 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 | |
from itertools import cycle | |
from faker import Faker | |
fake = Faker() | |
teachers = cycle([fake.user_name(), fake.user_name()]) | |
classes = cycle(["Math", "English", "Physics"]) | |
def create_fake_student_data(n=10): | |
rows = [] | |
for _ in range(n): | |
rows.append({'email': fake.email(domain="pybit.es"), | |
'class': next(classes), | |
'teacher': next(teachers)}) | |
return rows | |
def create_students_csv(rows, filename="students.csv"): | |
with open(filename, 'w', newline='') as csvfile: | |
fieldnames = ['email', 'class', "teacher"] | |
writer = csv.DictWriter(csvfile, fieldnames=fieldnames) | |
writer.writeheader() | |
writer.writerows(rows) | |
if __name__ == "__main__": | |
rows = create_fake_student_data(100) | |
create_students_csv(rows, "students2.csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment