title: Python. ValueError could not convert string to float:
body: <p>I'm trying to produce the average of numbers in a specified column in a text file. I am receiving an error that python could not convert string to float, although I don't see where I could be passing it an invalid string. </p>
  
  <pre><code>def avg_col(f, col, delim=None, nhr=0):
      """
      file, int, str, int -&gt; float
  
      Produces average of data stored in column col of file f
  
      Requires: file has nhr header rows of data; data is separated by delim
  
      &gt;&gt;&gt; test_file = StringIO('0.0, 3.5, 2.0, 5.8, 2.1')
      &gt;&gt;&gt; avg_col(test_file, 2, ',', 0)
      2.0
  
      &gt;&gt;&gt; test_file = StringIO('0.0, 3.5, 2.0, 5.8, 2.1')
      &gt;&gt;&gt; avg_col(test_file, 3, ',', 0)
      5.8
      """
      total = 0 
      count = 0
  
  
      skip_rows(f, nhr)
      for line in f: 
          if line.strip() != '':
              data = line.split(delim)
              col_data = data[col]
              total = sum_data(col_data) + total
              count = len(col_data) + count 
      return total / count
  
  def sum_data(lod):
      '''
      (listof str) -&gt; Real 
  
      Consume a list of string-data in a file and produce the sum
  
      &gt;&gt;&gt; sum_data(['0'])
      0.0
      &gt;&gt;&gt; sum_data(['1.5'])
      1.5
  
      '''
      data_sum = 0
      for number in lod: 
          data_sum = data_sum + float(number)
      return data_sum
  </code></pre>