Skip to content
Advertisement

Issue with writing CSV in Python

I am reading and XLSX file. and looping over the rows and colums to remove all the clutter from the excel.

JavaScript

When I print full_data_row it prints the string with , so that is correct. When i check my csv file. I get this as an ouput:

header1,header2,header3 O,p,z,e,t, ,h,o,s,t,e,d,

Advertisement

Answer

csvwriter.writerow() expects an iterable (e.g. a list), and will handle the formatting (placing commas between values) for you. Therefore, it parses your string as a list (of characters), printing commas between every character.

An alternative approach could be:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement