Deleting blank rows and rows with text in them at the same time
<p>New to programming here. After going through google and the forums (aswell as much trial and error), I couldn't find a neat solution to my problem.</p>

<p>I'd like to delete a few initial rows (first 10 rows) in my spreadsheet/CSV file and while I did find the solution to that using:</p>

<pre><code>    all(next(read) for i in range(10))
</code></pre>

<p>It does not appear to be able to delete the blank rows in the CSV file that I have. The first 10 rows I'd like to delete include those blank rows. I think the above line only deletes the rows if there are strings in them.</p>

<p>My full code is this so far [EDIT1]: Maybe this could work?</p>

<pre><code>    import csv
    with open('filename.csv') as csvfile:
       non_blank_row=[]
       filecsv = csv.reader(csvfile, delimiter=",")
       for row in filecsv:
              non_blank_row.append(row)

       better_blank_row = non_blank_row[[i for i in range(len(non_blank_row)) if non_blank_row!=[]
</code></pre>

<p>[EDIT2]: When I tried to print(better_blank_row), I did:</p>

<pre><code>    for i in better_blank_row:
        print(better_blank_row)
</code></pre>

<p>However, I'm not sure why output doesn't come out.. like the shell just freezes.
Any help would be much appreciated!</p>

<p>Your for loop is just iterating over <em>filecsv</em>. It's not doing anything.
You want something like</p>

<p><code>non_blank_rows = []
 for row in filecsv:
    if row: # empty strings are false-y
       non_blank_rows.append(row)</code></p>

<p>Now at this point you could just set filecsv to be non_blank_rows. 
Note that the more pythonic way to do all of this would probably be to use a list comprehension. I'd write the syntax for that, but if that's something you haven't heard about you might want to look them up on your own.</p>

<p><code>filecsv = [row for row in filecsv if row]</code> </p>

python csv rows