Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.5 kB
1
Indexable
Never


#list for data
data = []

#read data from bad data file
with open('badDataFile.txt') as file:
    for dt in file:
        data.append(dt.rstrip())
        
        
#open dataFile in write mode
dataFile = open('dataFile.txt', 'w')

#write header
dataFile.write('Data Points\n')
dataFile.write('_____________\n')

#iterate data
for dt in data:
    
    #take out space separated values from each data
    values = dt.split()
    
    #iterate values
    for v in values:
        
        #if value is numeric
        if v.isnumeric() and len(v) >= 3:
            
            #add value to data and break loop for current values
            dataFile.write(v)
            dataFile.write('\n')
            break
        
#close data file
dataFile.close()


badDataFile.txt (not all values are written, this is a sample file it will work for actual values similarly)

Datapoint: X1 = 986
Datapoint: X2 = 988
Datapoint: X3 = 989
Datapoint: X4 = 923
Datapoint: X5 = 985
Datapoint: X6 = 942
Datapoint: X7 = 922
Datapoint: X8 = 981
Datapoint: X9 = 1000
Datapoint: X10 = 1001
...
Datapoint: X21 = 1045
Datapoint: X22 = 1012
Datapoint: X23 = 1022
Datapoint: X24 = 984
Datapoint: X25 = 913
Datapoint: X26 = 998
Datapoint: X27 = 1043
...
Datapoint: X197 = 1002
Datapoint: X198 = 1067
Datapoint: X199 = 1016
Datapoint: X200 = 1019

dataFile.txt

Data Points
_____________
986
988
989
923
985
942
922
981
1000
1001
1045
1012
1022
984
913
998
1043
1002
1067
1016
1019