Created
January 19, 2017 13:59
-
-
Save AlanHohn/293c98f9dadfc67443b8078d843d4401 to your computer and use it in GitHub Desktop.
Generate a random CSV in Python
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
#!/usr/bin/python | |
import csv | |
import random | |
records=9000000 | |
print("Making %d records\n" % records) | |
fieldnames=['id','name','age','city'] | |
writer = csv.DictWriter(open("people.csv", "w"), fieldnames=fieldnames) | |
names=['Deepak', 'Sangeeta', 'Geetika', 'Anubhav', 'Sahil', 'Akshay'] | |
cities=['Delhi', 'Kolkata', 'Chennai', 'Mumbai'] | |
writer.writerow(dict(zip(fieldnames, fieldnames))) | |
for i in range(0, records): | |
writer.writerow(dict([ | |
('id', i), | |
('name', random.choice(names)), | |
('age', str(random.randint(24,26))), | |
('city', random.choice(cities))])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment