Python read particular cell value in excel
<p>I have an exel file named "123.csv" that is the output i get when running a PROM functionality, consisting of two columns "case" and "event". I want to modify this output by grouping events based on case. More specifically i want to write a python script that will group events that belong to the same case to be merged in a new cell, no mate what the length of my initial matrix is.Could anyone please give me some idea?
<a href="http://i.stack.imgur.com/ln2QK.png" rel="nofollow">curent and desiret output</a></p>

<pre><code>import csv

with open('123.csv', 'rb') as csvfile:
    spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
    for row in spamreader:
       print ', '.join(row).replace(',',' ').replace('"',' ') 
</code></pre>

<p>this is a part i wrote, but it only reads the file and removes some punctiation</p>

<p>You can use groupby from itertools to do this for you. Example of this:</p>

<pre><code>from itertools import groupby

current = [(101, 'A'), (101, 'B'), (101, 'Y'), (102, 'C'), (102, 'D'), (102, 'U')]
desired = []

for key, group in groupby(current, lambda x: x[0]):
    lst = [element[1] for element in group]
    grouped = (key, lst)
    desired.append(grouped)

print(desired)
</code></pre>

<p>Basically you give groupby the array of what you have now and an lambda function that takes the first element of the array (the array need to be sorted). Groupby will use first element to group elements by it.</p>

python csv