Note that there are some explanatory texts on larger screens.

plurals
  1. POPython CSV delimeter defaulting to ' '?
    primarykey
    data
    text
    <p>I'm trying to open, convert, manipulate and save a test CSV file for a larger project. So far I have opened the file, converted it to a list of lists and manipulated it. But I can't save it as a properly formatted CSV file.</p> <p>At the moment, it saves, but the delimeter for each column seems to be <code>' '</code> for some unknown reason. My data set is based on sold house prices/locations/dates so whenever there is a break in the time (between the data and time), and the locations ( between the street name, town etc.) I get a new column, whereas all the other data which doesn't have any whitespace (price, id number etc.) are all put into the same column, screwing up my data.</p> <p>On another note, for some odd reason my csv file keeps several empty rows between each row. I have no idea what's going on.</p> <p>This is the questionable part of the code:</p> <pre><code>def write_new_file(lst, new_file): '''(lst)-&gt;.CSV file Takes a list and writes it into a .CSV file. ''' writer = csv.writer(new_file, delimiter=',') writer.writerows(lst) new_file.close() </code></pre> <p>Here is my output in the shell:</p> <pre><code>&gt;&gt;&gt; doc[0] ['{AACDC187-2E3E-4705-BCF3-0001C4187ADD},', '208000,', '28/06/2013 00:00,', 'AL23HX,', 'F,', 'N,', 'L,', '17,', ',', 'TENNYSON ROAD,', ',', 'ST ALBANS,', 'ST ALBANS,', 'HERTFORDSHIRE,'] </code></pre> <p>Any help is appreciated!</p> <p>edit: I've been programming for all of a couple weeks so sorry if I'm an idiot!</p> <p>Edit 4:</p> <p>I've changed my code to use the csv.reader function, which works great and makes it the programme a lot smaller. It looks like this now:</p> <pre><code> #create an empty variable doc= [] with open(file2, 'r') as f: reader = csv.reader(f, delimiter=',') for row in reader: doc.append(row) </code></pre> <p>Here is my shell output:</p> <pre><code> &gt;&gt;&gt; doc[0] ['{AACDC187-2E3E-4705-BCF3-0001C4187ADD}', '208000', '28/06/2013 00:00', 'AL2 3HX', 'F', 'N', 'L', '17', '', 'TENNYSON ROAD', '', 'ST ALBANS', 'ST ALBANS', 'HERTFORDSHIRE', 'A'] </code></pre> <p>But my CSV output is the same, the columns are separated according to whitespace within the strings and not according to the commas separating the list items. And there is still an empty row between rows.</p> <p>My writing function is unchanged.</p> <p>Final edit: Solved! calc was screwing up in the end, not Python.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload