Rearrange sloppy CSV file in python?
<p>I received some CSV data that is pretty sloppy. I would like to arrange it in python, but a few things are throwing me for a loop. Below are the header and sample first rows of the CSV file.  </p>

<pre><code>PATIENT,MD,REFMD,DIAGNOSIS_HISTORY,AVAILABLE_STUDIES
"last name, first name &lt;odd character return&gt;
name id &lt;odd character return&gt;
name age",doctor name &lt;no quotes&gt;
doctor name 2 &lt;no quotes&gt;,"referring doctor last name, first name ",studies &lt;no quotes&gt;,"history line 1
history line 2&lt;odd character return&gt;
history line 3"&lt;odd character return&gt;
</code></pre>

<p>This is what I would like to data to look like at the end result.</p>

<pre><code>PATIENT,PATIENT ID, PATIENT AGE,MD1, MD2,REFMD,DIAGNOSIS_HISTORY,AVAILABLE_STUDIES
"name, name","name id","name age","doctor name","doctor name2","referring doctor last name, first name","studies","history line 1 history line history line 3"
</code></pre>

<p>I know I can do most of the rearranging with some for loops, but the character returns after the names, doctor name and history as well as the lack of quotes around the strings are confusing me.  </p>

<p>Any suggestions as to how to clean up the data prior to transposing things around?</p>