Python CSV help - matching from 1 field, outputs information from another field
Posted on 2014-10-03
Right now I am working with a csv file that I am basically trying to use conditions from 1 column to out put the information from another column. The csv looks like this:
What I would like to do is to basically filter based on the 1st field, and have the output be from field 2. This is the code I have so far:
for line in csv_file:
altl = line['typ1']
#cOut = altl + ', ' + line['typ2'] + '\n'
cn = line['typ2'].split("=") + '\n'
#the next 3 lines were to test the output
# if altl == 'aaa':
#print 'this needs to be an array:' + '\n' + cn
The next portion of the code is where I get stuck. I know how to do this in LUA, but I really really need to get better at python. In LUA, I would loop through, something like this
i = 1,#endofsameitems
while i == altl do
stuff with cn
Essentially I need the output to be:
print 'elements belonging to' + "'" altl "'" + ' :' + '\n' + cn
so that it looks something like this.
elements belonging to 'aaa':
How exactly can I go about that?