shell shift in exel using python
<p>i wrote the following python script that reads the contents of "prom output.csv"  file" and after does some processing it writes the output to the file "sorted output."</p>

<pre><code>import collections
import csv
import sys

with open("prom output.csv","r") as f:
    cr = csv.reader(f,delimiter=",")
    d=collections.defaultdict(lambda : list())
    header=next(cr)   
    for r in cr:
        d[r[0]].append(r[1])  


with open("sorted output.csv","w") as f:
    cr = csv.writer(f,sys.stdout, lineterminator='\n')
    cr.writerow(header)  
    od = collections.OrderedDict(sorted(d.items()))
    for k,v in od.items(): 
        cr.writerow([k,";".join(v)]) 
</code></pre>

<p>The output "sorted output.csv" looks like:</p>

<p><a href="http://i.stack.imgur.com/x3X63.png" rel="nofollow"><img src="http://i.stack.imgur.com/x3X63.png" alt="enter image description here"></a></p>

<p>My input file: "prom output.csv"  looks like:</p>

<p><a href="http://i.stack.imgur.com/gRq3a.png" rel="nofollow"><img src="http://i.stack.imgur.com/gRq3a.png" alt="enter image description here"></a></p>

<p>I want to slightly modify the current output so that it will have the following form:</p>

<p><a href="http://i.stack.imgur.com/D26C4.png" rel="nofollow"><img src="http://i.stack.imgur.com/D26C4.png" alt="enter image description here"></a></p>

<p>Any ideas?</p>

<p>Don't use <code>join</code> for your row content; just combine the header w/ the data into a single list:</p>

<pre><code>cr.writerow([k]+v) 
</code></pre>

python excel