Remove leading and trailing whitespace from a csv file with Pythonhttps://www.saltycrane.com/blog/2011/08/remove-leading-and-trailing-whitespace-csv-file-python/#comments2011-12-13T14:29:24-08:00Comment by Johannes
2011-12-13T14:29:24-08:00https://www.saltycrane.com/comments/cr/18/331/#c43354
<p>Although not a python solution, you may be interested in looking into <a href="http://code.google.com/p/google-refine/">Google Refine</a> for tasks like this. It makes cleaning up CSV data a breeze. It also has support for Jython so you can run Python expressions on the data.</p>
Comment by Eliot
2011-10-21T10:09:40-07:00https://www.saltycrane.com/comments/cr/18/331/#c39993
<p>Tom: <br />
It actually creates another generator so it won't load all values into memory at one time.</p>
<pre><code>print type(reader)
</code></pre>
<p>gives:</p>
<pre><code><type 'generator'>
</code></pre>
<p>If you make it a list instead of a generator (change the parentheses to square brackets), it will load all values into memory at one time:</p>
<pre><code>reader = [
dict((k, v.strip()) for k, v in row.items()) for row in reader]
print type(reader)
</code></pre>
<p>gives:</p>
<pre><code><type 'list'>
</code></pre>
Comment by Tom
2011-10-21T06:54:18-07:00https://www.saltycrane.com/comments/cr/18/331/#c39986
<p>Wouldn't this load all the csv values into memory? And is this a practical solution for large data-sets?</p>