-2
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 for everyone who continued to read. My dilemma is that I have a CSV with missing rows of data. There are two columns, One starting with a row of numbers (Like DKTM00001) and ending with a row (DKTM000008) as stated The columns repeat like this for the numbers, but in some cases, a row of numbers end up missing (Stated above). I want to find those row of missing numbers and output them to the screen. (I would ask to put them to a output file, but I want to do this, to teach myself Python.)

An example of the desired output:

DKTM 00018     DKTM 00028
DKTM 00039     DKTM 00049

Thank you in advance! I'm relatively new to Python 3.6.2, so I thought this would be a good exercise. Guess I bit off more than I can chew. I utilized this explanation as a basis(Efficient way to find missing elements in an integer sequence), but downshift's method helped me with the desired output a lot more.

  • 1
    What have you tried and where are you stuck? This is not a code-writing service – Dan Sep 11 '17 at 21:57
  • @SomeNewPythonGuy: To get a proper answer you should produce a reproducible version of your code. – Beta Sep 12 '17 at 17:25
  • My apologies gentleman. I looked at the link for a general idea as to how I wanted the code to work, but got lost as the code needed a different output. I'm so sorry if I was seeming like I wanted a free code for nothing. I didn't want to give that impression. – SomeNewPythonGuy Sep 13 '17 at 16:36

1 Answers1

0

Something like this may help you get started.

I'm not too clear on the content layout of your csv file (or which version of python you are using), but using a csv file with this content:

DKTM00001,DKTM00009
DKTM00002,DKTM00010
DKTM00003,DKTM00011

DKTM00005,DKTM00013
DKTM00006,DKTM00014

DKTM00008,DKTM00016

we can read the file using the csv module:

import csv

with open('data.csv') as csvfile:
    reader = csv.reader(csvfile)
    for line, row in enumerate(reader, 1):
        if not row:
            print 'line:', line, 'contents:', row

Output:

line: 4 contents: []
line: 7 contents: []

The enumerate function is useful in this situation since we want to count rows and print which lines are empty. Here I've passed 1 as the start parameter to enumerate to offset the line count starting from 1 instead of the default 0.

Modify as needed for your specific Python version. Feel free to comment for any clarification or modification.

Hope this helps.

  • Thank you so much, downshift! Yes it's a great step. I'm using Python 3.6.2. I'm so sorry for not displaying my code. I'll find my original code shortly if I can. But yes, the code was supposed to do something along the lines of.............. Title 1 Title 2 DKTM00013,DKTM00024 For the the lines of codes that are missing – SomeNewPythonGuy Sep 12 '17 at 15:34
  • You're very welcome, it would help if you included any code or sample inputs and expected outputs so we can compose an better solution. Feel free to [edit](https://stackoverflow.com/posts/46164858/edit) and update your question with any more information (consider using the formatting tools in the question form, as comments lack formatting) so we can create a better solution. and thanks for your feedback! – chickity china chinese chicken Sep 12 '17 at 16:57
  • Thank you! I updated my original comment, so as to reflect the changes you've mentioned. Hope that helps! And again, thank you so much! – SomeNewPythonGuy Sep 13 '17 at 14:06