title: Compare 2 different csv files and output all the changes into a new csv
body: <p>I have 2 CSVs which are New.csv and Old.csv shown below:</p>
  <p>Old.csv</p>
  <pre><code>longName,shortName,eventType,number,severity
  ACTAGENT201,ACAT201,RES,1,INFO
  ACTAGENT202,ACAT202,RES,2,ALERT
  ACODE801,AC801,ADMIN,1,MINOR
  ACODE802,AC802,ADMIN,2,MINOR
  ACODE102,AC102,COMM,2,CRITICAL
  ACODE103,AC103,COMM,3,CRITICAL
  ACODE104,AC104,COMM,4,CRITICAL
  ACODE105,AC105,COMM,5,CRITICAL
  ACODE106,AC106,COMM,6,CRITICAL
  </code></pre>
  <p>New.csv</p>
  <pre><code>longName,shortName,eventType,number,severity
  ACTAGENT201,ACAT201,RES,1,INFO
  ACTAGENT202,ACAT202,RES,2,ALERT
  ACODE801,AC801,ADMIN,1,MINOR
  ACODE802,AC802,ThisHasBeenChanged,2,MINOR
  ACODE102,AC102,COMM,2,CRITICAL
  ACODE103,AC103,COMM,3,CRITICAL
  ACODE104,AC104,COMM,4,THISHASBEENCHANGED
  ACODE105,AC105,COMM,5,CRITICAL
  ACODE106,AC106,COMM,6,CRITICAL
  </code></pre>
  <p>If there is data in one of the columns in the row that has been modified/changed between the old.csv and the new.csv then that whole row should be appended to the changes.csv like this with each column from old.csv and new.csv beside each other:</p>
  <p><a href="https://i.stack.imgur.com/3Uqgn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3Uqgn.png" alt="enter image description here" /></a></p>
  <p>I know how to find new and deleted items in the csv, but could not figure out how to get the modified items. Code below:</p>
  <pre><code>import csv
  
  def DeletedItems(old_csv, new_csv, changes_csv):
      with open(new_csv, newline=&quot;&quot;, encoding=&quot;utf8&quot;) as new_fp:
          csv_reader = csv.reader(new_fp)
          csv_headings = next(csv_reader)
          new_long_names = {row[0] for row in csv.reader(new_fp)}
      with open(old_csv, newline=&quot;&quot;, encoding=&quot;utf8&quot;) as old_fp:
          with open(changes_csv, &quot;a&quot;, newline=&quot;&quot;, encoding=&quot;utf8&quot;) as changes_fp:
              writer = csv.writer(changes_fp)
              writer.writerow(&quot;&quot;)
              for row in csv.reader(old_fp):
                  if row[0] not in new_long_names:
                      writer.writerow(row)
  
  def NewItems(old_csv, new_csv, changes_csv):
      with open(old_csv, newline=&quot;&quot;, encoding=&quot;utf8&quot;) as old_fp:
          csv_reader = csv.reader(old_fp)
          csv_headings = next(csv_reader)
          old_long_names = {row[0] for row in csv.reader(old_fp)}
      with open(new_csv, newline=&quot;&quot;, encoding=&quot;utf8&quot;) as new_fp:
  
          with open(changes_csv, &quot;w&quot;, newline=&quot;&quot;, encoding=&quot;utf8&quot;) as changes_fp:
              writer = csv.writer(changes_fp)
              for row in csv.reader(new_fp):
                  if row[0] not in old_long_names:
                      writer.writerow(row)
  
  NewItems(&quot;old.csv&quot;, &quot;new.csv&quot;, &quot;changes.csv&quot;)
  DeletedItems(&quot;old.csv&quot;, &quot;new.csv&quot;, &quot;changes.csv&quot;)
  
  </code></pre>