title: In Python, how to compare two csv files based on values in one column and output records from first file that do not match second
body: <p>Pretty new to python and coding in general. I've been searching for several csv comparison questions and answers and couldn't find anything that helped with this specific comparison problem.</p>
  <p>I have two files that contain network asset info. Some devices have multiple IP addresses in one file, and only 1 address in another. Also they don't seem to share uppercase or lowercase format. I'm interested in their hostname values.</p>
  <p>(files don't have headers)</p>
  <p>file 1:</p>
  <pre><code>HOSTNAME1,10.0.0.1
  HOSTNAME2,10.0.0.2
  HOSTNAME3,10.19.0.3
  hostname4,10.19.0.4,10.19.17.31,10.19.17.32,10.19.17.33,10.19.17.34
  hostname5,10.19.0.40,10.19.17.51,10.19.17.52,10.19.17.53,10.19.17.54
  hostname6,10.19.0.55,10.19.17.56,10.19.17.57,10.19.17.58,10.19.17.59
  </code></pre>
  <p>File 2</p>
  <pre><code>HOSTNAME4,10.19.0.4
  HOSTNAME5,10.19.0.40
  HOSTNAME6,10.19.0.55
  hostname7,192.168.0.1
  hostname8,192.168.0.2
  hostname9,192.168.0.3
  </code></pre>
  <p>I'd like to compare these files based on hostname (column 0) and output to a third file that contains the rows in file1 that are NOT in file2, ignoring case, and ignoring if they have multiple IP's in file1 or file2.</p>
  <p>desired output:</p>
  <p>file3:</p>
  <pre><code>HOSTNAME1,10.0.0.1
  HOSTNAME2,10.0.0.2
  HOSTNAME3,10.19.0.3
  </code></pre>
  <p>I tried a simple comm command in bash to try and see if I could generate the desired result and had no luck, so I decided to try this in python</p>
  <pre><code>comm -23 --nocheck-order file1.csv file2.csv &gt; file3.csv
  </code></pre>
  <p>Here's what i've tried in python:</p>
  <pre><code>with open('file1.csv', 'r') as f1, open('file2.csv', 'r') as f2:
      fileone = f1.readlines()
      filetwo = f2.readlines()
  
  with open('file3.csv', 'w') as outFile:
      for line in fileone:
          if line not in filetwo:
              outFile.write(line)
  </code></pre>
  <p>Problem is it isn't writing the rows where the IP list don't match exactly. Even if in column 1 they  share a hostname, if the row has multiple ips in one file it isn't counted.</p>
  <p>I'm not sure my code above is ignore case and it seems to be trying to match the entire string from a row, rather than &quot;contains.&quot;</p>
  <p>willing to try pandas package if that makes more sense for this kind of comparison</p>