title: A function to read CSV data from a file into memory
body: <p>I am trying to create a function that reads a csv file into a memory in a list form. When I run my code, it gives me this error message (&quot;string indices must be integers&quot;). Were am I getting it wrong.
  Below is the code. Thanks for your help</p>
  <pre><code># create the empty set to carry the values of the columns
  
  Hydropower_heading = []
  Solar_heading = []
  Wind_heading = []
  Other_heading = []
  
  def my_task1_file(filename):                              # defines the function &quot;my_task1_file&quot;
      with open(filename,'r') as myNew_file:                # opens and read the file
          for my_file in myNew_file.readlines():            # loops through the file
  
  # read the values into the empty set created
              Hydropower_heading.append(my_file['Hydropower'])
              Solar_heading.append(my_file['Solar'])
              Wind_heading.append(my_file['Wind'])
              Other_heading.append(my_file['Other'])
  
  #Hydropower_heading = int(Hydropower)
  #Solar_heading = int(Solar)
  #Wind_heading = int(Wind)
  #Other_heading = int(Other)            
              
  my_task1_file('task1.csv')                                # calls the csv file into the function 
  
  # print the Heading and the column values in a row form
  print('Hydropower: ', Hydropower_heading)
  print('Solar: ', Solar_heading)
  print('Wind: ', Wind_heading)
  print('Other: ', Other_heading)
  </code></pre>