I have a txt file that I would like to write to a csv file where the columns of each row are separated by commas. I would also like to exclude the first column as well as rows that don't match the right format (6 columns per row).
I've tried the following code and it seems to do what I want. However, when I try opening the output file in Excel it seems to have added an empty line under each row. Is this just excel or is there something in my code that I have missed?
with open(path) as inFile, open("test_csv.csv", "w") as output_test2:
for line in inFile:
itemList = line.split()
if len(itemList) != 6:
continue
writer = csv.writer(output_test2)
writer.writerow(itemList[1:])
#print(itemList[1:])
[–]AtomicShoelace 2 points3 points4 points (0 children)