-
-
Save yelhady87/056f69bf428cdf1f3ab5c7aeb14fb39b to your computer and use it in GitHub Desktop.
Generate a random CSV in Python
This file contains hidden or 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