Skip to content

Instantly share code, notes, and snippets.

@richard-julien
Created July 4, 2024 11:20
Show Gist options
  • Save richard-julien/9cac61bab212da1f3f086d5d31080525 to your computer and use it in GitHub Desktop.
Save richard-julien/9cac61bab212da1f3f086d5d31080525 to your computer and use it in GitHub Desktop.
Simple csv generator
import csv
import random
import string
rows = 15000
columns = 3
print_after_rows = 100000
letters = string.ascii_lowercase
def generate_random_row(col):
a = []
l = [i]
for j in range(col):
l.append(''.join(random.choice(letters) for i in range(20)))
a.append(l)
return a
if __name__ == '__main__':
f = open('sample.csv', 'w')
w = csv.writer(f, lineterminator='\n')
for i in range(rows):
if i % print_after_rows == 0:
print(".", end="", flush=True)
w.writerows(generate_random_row(columns))
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment