Skip to content

Instantly share code, notes, and snippets.

@jomartin93
Forked from momota/generate_L_size_csv.py
Created February 20, 2023 02:00
Show Gist options
  • Select an option

  • Save jomartin93/45933bf13fcbc6b173c5dca6828e69b8 to your computer and use it in GitHub Desktop.

Select an option

Save jomartin93/45933bf13fcbc6b173c5dca6828e69b8 to your computer and use it in GitHub Desktop.
Generate a large size of CSV file was filled random values. This script generates around 250MB size of the file. You can adjust two parameters `row` and `col` to generate the file which has desirable size.
import csv
import random
# 1000000 and 52 == roughly 1GB (WARNING TAKES a while, 30s+)
rows = 1000000
columns = 52
def generate_random_row(col):
a = []
l = [i]
for j in range(col):
l.append(random.random())
a.append(l)
return a
if __name__ == '__main__':
f = open('sample.csv', 'w')
w = csv.writer(f, lineterminator='\n')
for i in range(rows):
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