title: Change Column Headers using DictWriter
body: <p>I am working on some code to produce two new CSV files from a input .txt file. The .txt file has 40 columns of data and I am writing two new csv files that only take in 2 columns from the .txt file each.</p>
  
  <p>My code is working great and producing almost exactly what i need. The last step is renaming the original headers in the two new csv outputs. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>import csv
  
  QATargetHeaders = ['FNAME','LNAME']
  FinalTargetHeaders = ['PROJECT_CODE','PHONE_NUMBER']
  
  with open('TEST.txt','r') as csv_input, open('Test_QA2.csv','w') as csv_output:
      reader = csv.DictReader(csv_input, delimiter='^')
      writer = csv.DictWriter(csv_output, fieldnames=QATargetHeaders, extrasaction='ignore')
      writer.writeheader()
      for line in reader:
          writer.writerow(line)
  with open('TEST.txt','r') as csv_input, open('Test_FINAL.csv','w') as csv_output:
      reader = csv.DictReader(csv_input, delimiter='^')
      writer = csv.DictWriter(csv_output, fieldnames=FinalTargetHeaders, extrasaction='ignore')
      writer.writeheader()
      for line in reader:
          writer.writerow(line)
  </code></pre>
  
  <p>For TEST_QA2.csv, i need to change the headers:</p>
  
  <pre><code>FNAME = First Name
  LNAME = Last Name
  </code></pre>
  
  <p>For TEST_FINAL.csv, i need to change the headers:</p>
  
  <pre><code>PROJECT_CODE = PROJECT ID
  PHONE_NUMBER = DEVICE1
  </code></pre>
  
  <p>Can someone help me figure out how to rewrite the headers here? The TargetHeaders must be defined as the exact column names from the .txt file so my writer knows what to copy in. Thank you in advance</p>