My data looks something like this:
data = [
[" trailing space", 19, 100],
[" ", 19, 100],
]
writer = csv.writer(csv_filename, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
Output
trailing space,19,100
,19,100
What I want
" trailing space",19,100
" ",19,100
Python default CSV writer has the option to "QUOTE_MINIMAL" but it doesn't include quoting strings with extra spaces in it. In my case, those empty spaces are actually critical, but without quoting, the reader (like libre-office) strips the spaces if not quoted.
Is there any built in options or quick cheap way to tell the writer to quote empty strings with spaces?
Also, "QUOTE_NONNUMERIC" is quoting too much. The actual data is huge ( few hundred megabytes with 60% - 70% of strings). It may sounds silly, but I'm trying to reduce the csv size by minimizing the quotes.