I need the lines that comply
lect_linea[0]=='"PseudorangeRateUncertaintyMetersPerSecond"'and float(lect_linea[60])>30
Sort from lowest to highest by the value stored in lect_linea[60]
I've tried using:
g.write(sorted(linea, key=lambda x: float(x[60])))
instead of:
g.write(linea)
but it gives me a syntax error. These would be one of several lines of the input file:
"Number_of_sentences_for_full_data" ", 4," "Elevation_Degrees" ", 74," "Azimuth_degrees" ", 35," "Sentence_1_of_2" ", 1," "Number_of_satellites_in_view" ", 14," "Satellite_PRN_number" ", 27, "" SNR "", "" 42 "", "" CheckSum_data "", 10, "" Satellites_in_view "", "" $ GPGSV "", "" Id "", "" NMEA GSV "" " "Latitude" ", 3928.752338," "HorizontalDilutionofPosition" ", 0.4," "TimeinSecondsSinceLastDGPSUpdate" "," "51.1" "," "Address_length" "," "W" "," "GlobalPositioningSystemFixData" "," "$ GPGGA" "," "Address_Latitude" "," "N" "," "FixQuality" ", 1," "DGPSStationIDNumber" "," "51.1" "," "Altitude" ", 19.6," "Geoid_height_units" "," " M "", "" ChecksumData "", "" M "", "" Fixtakenat_hh_mm_ss_UTC "", 163504, "" NumberofSatellitesTracked "", 28, "" Geoid_height "", 51.1, "" Altitude_units "", "" M " "," "Id" "," "NMEA GGA" "," "Length" ", 20.256369" "PseudorangeRateUncertaintyMetersPerSecond" ", 4.2033262571598," "DriftUncertaintyNanosPerSecond" "," "" "," "AccumulatedDeltaRangeState" ", 4," "ReceivedSvTimeNanos" ", 491721918491620.0," "TimeUncertaintyNanos" "," "" "," "SnrInDb" " , "" "", "" FullBiasNanos "", -1.2125108815424e + 18, "" State "", 47, "" MultipathIndicator "", "" 1 "", "" AgcDb "", "" "", " "PseudorangeRateMetersPerSecond" ", -4.2472825078449," "TimeNanos" ", 40458000000," "Svid" ", 7," "AccumulatedDeltaRangeUncertaintyMeters" ", 3.4028234663853e + 38," "AccumulatedDeltaRangeMeters" ", -139.4196963987," "BiasUncertaintyNanos" ", 5.3149323606571, "" BiasNanos "", 0, "" CarrierPhaseUncertainty "", "" "", "" CarrierFrequencyHz2 "", "" \ n "", "" TimeOffsetNanos "", 0, "" DriftNanosPerSecond "", "" "", "" CarrierFrequencyHz "", "" "", "" ConstellationType "", "" 1 "", "" CarrierCycles "", "" "", "" ReceivedSvTimeUncertaintyNanos "", 167, "" CarrierPhase "" , "" "", "" LeapSecond "", "" "", "" HardwareClockDiscontinuityCount "", 0, "" ElapsedRealtimeMillis "", 14068885, "" Id "", "" Raw "", " "Cn0DbHz" ", 16.816381454468" "GPS_time" "," "2018-06-08 16,35,21" "," "Altitude" ", 70.782148," "Longitude" ", -0.33762," "Provider" "," "gps" "," "Latitude" ", 39.479188," "Speed" ", 0," "Id" "," "Fix" "," "Accuracy" ", 4"
This is my code:
f=open('C:\Users\Xabier\Desktop\good_shit.txt','r')
g = open("middle.txt","w")
#h = open("end.txt","w")
while True:
linea=f.readline()
if not linea:break
full_linea=linea.splitlines()
lect_linea=linea.split(',')
if (lect_linea[0]=='"PseudorangeRateUncertaintyMetersPerSecond"'and float(lect_linea[60])>30):
#print (linea)
g.write(linea)
elif (lect_linea[0]=='"Number_of_sentences_for_full_data"'and float(lect_linea[3])>20 and float(lect_linea[9])>4):
#print (linea)
g.write(linea)
elif (lect_linea[0]=='"GPS_time"'):
#print (linea)
g.write(linea)
f.close()
g.close()