I am supposed to generate a csv file with 10 columns (from A to J) with 10000 rows that contain random numbers between 1 to 1000. I am able to get the desired output but cannot write this output to a csv file. Please find my code and the generated error message below.
import random
import csv
with open('table.csv', 'w') as file:
csv_write = csv.writer(file,delimiter="\t")
for i in range(ord('A'), ord('J')+1):
csv_write.writerow(chr(i), end="\t")
for j in range(1,11):
for k in range(1,1001):
csv_write.writerow(random.randint(1,10001), end="\t")
Error Message
Traceback (most recent call last):
File "C:\Users\rida_\Desktop\tables.py", line 8, in <module>
csv_write.writerow(chr(i), end="\t")
TypeError: writerow() takes no keyword arguments
writerow()should take keywords for some reason? You indentation is off by the way, please fix it so that it is more readable for us.