Concatenate/join Rows In Txt File W/ Python 3
Looking to clean up a .txt file from NMEA GPS. My current code is below. deletes = ['$GPGGA', '$GPGSA', '$GPGSV', '$PSRF156', ] searchquery = '$GPRMC' with open('Drive_home.txt_rf
Solution 1:
You can do something like:
deletes = ['$GPGGA', '$GPGSA', '$GPGSV', '$PSRF156', ]
searchquery = '$GPRMC'withopen('Drive_home.txt_rf') as f1, open('Drive_home_1.txt', 'w+') as f2:
lines = f1.readlines()
for i, line inenumerate(lines):
if line.startswith(searchquery) andnotany(delete in lines[i + 1] for delete in deletes):
f2.write(f'{line.rstrip()}{lines[i+1]}')
think it will work, no?
Baca Juga
- My Python Code That Converts Numbers Between Bases Has Several Errors. What Could Be Wrong And How Can I Find Them?
- Pandas.io.common.cparsererror: Error Tokenizing Data. C Error: Buffer Overflow Caught - Possible Malformed Input File
- If Row In Dataframe Starts With Keyword, Concat It With The Row Above
Post a Comment for "Concatenate/join Rows In Txt File W/ Python 3"