Question: 1. First lets determine how many lines are in the data file. This is simple we can just open the file in a text editor
1. First lets determine how many lines are in the data file. This is simple we can just open the file in a text editor and count them. But what if the file is too large to load into notepad? Or if the file has some garbage and needs to be cleaned by removing the garbage lines.
for input in f: 10 input.strip(' ').split(',') tokens 11 %3D countAll = countAll + 1 12 13 # Check each element to see if it contains a 'N/A' 14 coll = tokens[0] 15 if (col1 == 'NA'): continue 16 tokens[1] col2 = 17 if (col2 == 'NA'): continue tokens [2] 18 col3 = 19 if (col3 == 'NA'): continue col4 = tokens[3] 20 21 if (col4 == 'NA'): continue tokens [4] 22 col5 = 23 if (col5 == 'NA'): continue tokens [5] 24 col6 = 25 %3D if (col6 == 'NA'): continue col7 = tokens[6] 26 27 if (col7 == 'NA'): continue 28 29 # What the remaining lines countRemaining = countRemaining + 1 30 31 32 33 # Output the line o. write(input) 34 35 + str(countAll)) + str(countRemaining)) print('Count of all lines print('Count of filtered lines 36 37 o.close() 38 f.close() 39 for input in f: 10 input.strip(' ').split(',') tokens 11 %3D countAll = countAll + 1 12 13 # Check each element to see if it contains a 'N/A' 14 coll = tokens[0] 15 if (col1 == 'NA'): continue 16 tokens[1] col2 = 17 if (col2 == 'NA'): continue tokens [2] 18 col3 = 19 if (col3 == 'NA'): continue col4 = tokens[3] 20 21 if (col4 == 'NA'): continue tokens [4] 22 col5 = 23 if (col5 == 'NA'): continue tokens [5] 24 col6 = 25 %3D if (col6 == 'NA'): continue col7 = tokens[6] 26 27 if (col7 == 'NA'): continue 28 29 # What the remaining lines countRemaining = countRemaining + 1 30 31 32 33 # Output the line o. write(input) 34 35 + str(countAll)) + str(countRemaining)) print('Count of all lines print('Count of filtered lines 36 37 o.close() 38 f.close() 39
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
