title: Removing rows and columns in python CSV module
body: <p>I promise I searched and read several pages of google before I came to make this post. Due diligence has been done I swear.</p>
  
  <p>I am trying to open a CSV file in python, read the file, make changes to it, and then write out a new file.</p>
  
  <p>I got this far:</p>
  
  <pre><code>import csv
  def water_data ():
      with open('aquastat.csv', 'r') as csv_file:
          csv_reader = csv.reader(csv_file)
          final_file_name = "final_water.data.csv"
          final_file = open(final_file_name,'w')
          csv_writer = csv.writer(final_file,delimiter="\t")
          for row in csv_reader:
              csv_writer.writerow(row)
  </code></pre>
  
  <p>But I'm struggling to get any further. I want to remove certain columns, but I cannot comprehend how python will know the difference between a row and a column. For example, the columns are <code>Area, Area ID, Year, Value</code>, etc. I only want <code>Area, Year, Value</code>. I tried </p>
  
  <pre><code>for row in final_file:
  
  final_file.writerow(row[0] + row[2] + row[4] + row[5])
  </code></pre>
  
  <p>but I kept getting the following error: IndexError: list index out of range</p>
  
  <p>[I would also like to replace blank cells with a *, but the column thing is the priority]</p>
  
  <p><em>Note that I cannot use Pandas</em></p>
  
  <p>If possible I would really appreciate if someone could not just tell me the code but explain it to me so I can figure it out further myself.</p>
  
  <p><strong>TLDR: How can I remove empty rows from the CVS file and write only certain columns into the new file?</strong> </p>
  
  <p><strong>INPUT:</strong></p>
  
  <pre><code>"Area","Area Id","Variable Name","Variable Id","Year","Value","Symbol","Md" 
  "Afghanistan",2,"Total area of the country",4100,1977,65286.0,"E","",""
  "Afghanistan",2,"Total area of the country",4100,1982,65286.0,"E","","" 
  "Afghanistan",2,"Total area of the country",4100,1987,65286.0,"E","",""
  "Afghanistan",2,"Total area of the country",4100,1992,65286.0,"E","","" 
  "Afghanistan",2,"Total area of the country",4100,1997,65286.0,"E","",""
  "Afghanistan",2,"Total area of the country",4100,2002,65286.0,"E","",""
  </code></pre>