Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed1. 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions