title: How do I remove blank rows from a CSV file in python?
body: <p>Good evening! I'm currently working on a python 3 script to create a CSV file with specified columns of data. I'm really close to finalizing it, but I've run into a problem I just can't get past.</p>
  
  <p>Basically, I'm trying to add two values (floats) together from two columns and append them to another column; however, when the program runs into blank lines (strings), everything goes kaput. As far as I know converting the whole csv file to a float isn't possible, so I've decided to just delete these blank lines... how do I do that?</p>
  
  <p>Also, if anyone has any suggestions for a cleaner way to do this I'd be more than glad to hear it!</p>
  
  <p>My code is as follows:</p>
  
  <pre><code>#! python3
  # automatedReport.py - Reads and writes a new CSV file with
  # Campaign Name, Group Name, Raised from Apr 1st-Apr 30th Total,
  # Donation from Apr 1st-Apr 30th Total, and Campaign Total Apr 1st-Apr 30th.
  
  import csv, os, ctypes
  MessageBox = ctypes.windll.user32.MessageBoxW
  total = 0
  
  # Find out whether or not campaign_monthly_report is present.
  if os.path.isfile('campaign_monthly_report.csv'):
      os.makedirs('automatedReport', exist_ok=True)
      print('Organizing campaign_monthly_report.csv...')
  
      #Read the CSV file.
      with open('campaign_monthly_report.csv', 'r') as csv_file:
          csv_reader = csv.DictReader(csv_file)
  
          #Write out the CSV file.
          with open(os.path.join('automatedReport', 'automated_campaign_monthly_report.csv'), 'w', newline='') as new_file:
              fieldnames = ['Campaign Name','Group Name','Raised from Apr 1st-Apr 30th Total','Donation from Apr 1st-Apr 30th Total', 'Campaign Total Apr 1st-Apr 30th']
  
              csv_writer = csv.DictWriter(new_file, fieldnames=fieldnames)
  
              csv_writer.writeheader()
  
              #Sloopy code, I know. I'm a bit new to this.
              for line in csv_reader:
                  del line['Contact Name']
                  del line['Contact Phone']
                  del line['Contact Email']
                  del line['Sign Ups']
                  del line['Active Members']
                  del line['% Active Members']
                  del line['Raised upto Mar 31st 1st Time']
                  del line['Raised upto Mar 31st Everyday']
                  del line['Raised upto Mar 31st Total']
                  del line['Raised upto Mar 31st Target']
                  del line['Donation upto Mar 31st Group']
                  del line['Donation upto Mar 31st PF']
                  del line['Donation upto Mar 31st Total']
                  del line['Additional $ Applied upto Mar 31st']
                  del line['Raised from Apr 1st-Apr 30th 1st Time']
                  del line['Raised from Apr 1st-Apr 30th Everyday']
                  del line['Raised from Apr 1st-Apr 30th Target']
                  del line['Donation from Apr 1st-Apr 30th Group']
                  del line['Donation from Apr 1st-Apr 30th PF']
                  del line['Additional $ Applied from Apr 1st-Apr 30th Total']
                  del line['Date Joined']
  
                  total = float(line['Raised from Apr 1st-Apr 30th Total']) + float(line['Donation from Apr 1st-Apr 30th Total'])
                  csv_writer.writerow(line)
                  print (total)
  
              MessageBox(None, 'Process Complete. Locate ouput in the automatedReport folder.', ' Success!', 0)
  else:
      MessageBox(None, 'campaign_monthly_report not found!', ' Error!', 0)
  </code></pre>
  
  <p><strong>Error message:</strong></p>
  
  <pre><code>Traceback (most recent call last):
  File "C:\Users\Mende\Desktop\Automated Campaign\automatedReport.py", line 51, in &lt;module&gt;
  total = float(line['Raised from Apr 1st-Apr 30th Total']) + float(line['Donation from Apr 1st-Apr 30th Total'])
  ValueError: could not convert string to float: &gt;&gt;&gt; 
  </code></pre>