python - combine selected lines/rows within a csv file -


i need combine lines ($gpgga , $gpvtg) within csv file python , have problem. csv file looks this:

~11:16:04.831,$gpgga,091606.00,5149.28020915,n,01140.54074205,e ~11:16:04.861,$gpvtg,40.8,t,,,000.05,n,000.09,k,d*75 ~11:16:05.833,$gpgga,091607.00,5149.28020818,n,01140.54074319,e ~11:16:05.863,$gpvtg,40.8,t,,,000.01,n,000.01,k,d*79 

i tried with

eingabe = sys.argv[1] open(eingabe, "rb") file:        datareader = csv.reader(file)     row in datareader:         if "$gpgga" in row:             col1 = row[0], row[1], row[3], row[5]         if "$gpvtg" in row:             col2 = row[0], row[1], row[2]         print col1 + col2 

the result final line, need of them

('~11:16:08.827', '$gpgga', '5149.28021200', '01140.54075064', '~11:16:08.867', '$gpvtg', '40.8')

how go achieving this?

>>> open('1.csv') file: ...     reader = csv.reader(file) ...     col1s = []; col2s = [] ...     row in reader: ...             if "$gpgga" in row: ...                     col1s.append((row[0], row[1], row[2], row[5])) ...             elif "$gpvtg" in row: ...                     col2s.append((row[0], row[1], row[2])) ...     each in zip(col1s, col2s): ...             print each[0] + each[1] ...  ('~11:16:04.831', '$gpgga', '091606.00', '01140.54074205', '~11:16:04.861', '$gpvtg', '40.8') ('~11:16:05.833', '$gpgga', '091607.00', '01140.54074319', '~11:16:05.863', '$gpvtg', '40.8') >>>  

Comments