Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #44556

how to compare two fields in python

X-Received by 10.224.215.194 with SMTP id hf2mr65173qab.0.1367343717040; Tue, 30 Apr 2013 10:41:57 -0700 (PDT)
X-Received by 10.50.28.81 with SMTP id z17mr2100530igg.13.1367343716989; Tue, 30 Apr 2013 10:41:56 -0700 (PDT)
Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!s14no1283256qam.0!news-out.google.com!ef9ni37798qab.0!nntp.google.com!s14no1308839qam.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.python
Date Tue, 30 Apr 2013 10:41:56 -0700 (PDT)
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=169.237.198.139; posting-account=OBjB_AoAAACT68y_UqSttHWjx82mbr9I
NNTP-Posting-Host 169.237.198.139
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <59afdc2b-ab76-40b6-8f63-4a562e288029@googlegroups.com> (permalink)
Subject how to compare two fields in python
From upendra kumar Devisetty <upendrakumar.devisetty@googlemail.com>
Injection-Date Tue, 30 Apr 2013 17:41:57 +0000
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Lines 17
Xref csiph.com comp.lang.python:44556

Show key headers only | View raw


I have a very basic question in python. I want to go through each line of the a csv file and compare to see if the first field of line 1 is same as first field of next line and so on. If it finds a match then i would like to put that field in an object1 else put that field in a different object2. Finally i would like to count how many of the fields in object1 vs object2. Can this be done in python? Here is a small example.

BRM_1   679 1929
BRM_1   203 567
BRM_2   367 1308
BRM_3   435 509
As you can see field1 of line1 is same as field2 of line2 and so that field BRM_1 should be place in object1 and BRM_2 and BRM_3 should be placed in object2. So the final numbers of object1 is 1 and object2 is 2.

Thanks in advance..

Upendra

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

how to compare two fields in python upendra kumar Devisetty <upendrakumar.devisetty@googlemail.com> - 2013-04-30 10:41 -0700
  Re: how to compare two fields in python Joel Goldstick <joel.goldstick@gmail.com> - 2013-04-30 13:53 -0400
  Re: how to compare two fields in python Fábio Santos <fabiosantosart@gmail.com> - 2013-04-30 19:08 +0100
  Re: how to compare two fields in python Tim Chase <python.list@tim.thechases.com> - 2013-04-30 13:19 -0500
    Re: how to compare two fields in python upendra kumar Devisetty <upendrakumar.devisetty@googlemail.com> - 2013-04-30 11:22 -0700
      Re: how to compare two fields in python Fábio Santos <fabiosantosart@gmail.com> - 2013-04-30 19:42 +0100
  Re: how to compare two fields in python Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-04-30 19:54 -0400

csiph-web