Skip to content

Instantly share code, notes, and snippets.

@yelhady87
Forked from AlanHohn/makecsv.py
Created October 5, 2020 16:10
Show Gist options
  • Select an option

  • Save yelhady87/056f69bf428cdf1f3ab5c7aeb14fb39b to your computer and use it in GitHub Desktop.

Select an option

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