我需要将 csv 文件中的行 ($GPGGA
和$GPVTG
) 与 python 结合起来,但有问题。csv 文件如下所示:
~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
我试过了
eingabe = sys.argv[1]
with open(eingabe, "rb") as file:
datareader = csv.reader(file)
for 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
结果只是最后一行,但我需要所有这些
('~11:16:08.827', '$GPGGA', '5149.28021200', '01140.54075064', '~11:16:08.867', '$GPVTG', '40.8')
我该如何实现这一目标?