How do I find missing number sequences in Python through Gap Analysis? -
title 1 title 2 dktm 00001 dktm 00008 dktm 00009 dktm 00017 dktm 00029 dktm 00038 dktm 00050 dktm 00061 dktm 00062 dktm 00073
thanks continued read. dilemma have csv missing rows of data. there 2 columns, 1 starting row of numbers (like dktm00001) , ending row (dktm000008) stated columns repeat numbers, in cases, row of numbers end missing (stated above). want find row of missing numbers , output them screen. (i ask put them output file, want this, teach myself python.)
an example of desired output:
dktm 00018 dktm 00028 dktm 00039 dktm 00049
thank in advance! i'm relatively new python 3.6.2, thought exercise. guess bit off more can chew. utilized explanation basis(efficient way find missing elements in integer sequence), downshift's method helped me desired output lot more.
something may started.
i'm not clear on content layout of csv
file (or version of python using), using csv
file content:
dktm00001,dktm00009 dktm00002,dktm00010 dktm00003,dktm00011 dktm00005,dktm00013 dktm00006,dktm00014 dktm00008,dktm00016
we can read file using csv module:
import csv open('data.csv') csvfile: reader = csv.reader(csvfile) line, row in enumerate(reader, 1): if not row: print 'line:', line, 'contents:', row
output:
line: 4 contents: [] line: 7 contents: []
the enumerate function useful in situation since want count rows , print lines empty. here i've passed 1
start
parameter enumerate
offset line count starting 1
instead of default 0
.
modify needed specific python version. feel free comment clarification or modification.
hope helps.
Comments
Post a Comment