title: How to create a CSV matrix based on csv file?
body: <p>I just learn python and I don't know where to start and go with my current project. I got a project to make a matrix that can show relation between color from a .csv file to another .csv file. The input and output file will be looked like this</p>
  
  <blockquote>
    <p>Input </p>
  
  <pre><code>black blue
  red blue
  blue black
  yellow black 
  </code></pre>
    
    <p>Output </p>
  
  <pre><code>             black   blue   red   yellow
  black          0      1      0      1
  blue           1      0      1      0
  red            0      1      0      0
  yellow         1      0      0      0
  ?```
  </code></pre>
  </blockquote>
  
  <p>By using this code, but .csv output doesn't show anything.</p>
  
  <pre><code>import csv
  import collections
  import itertools
  
  grid = collections.Counter()
  
  with open("color.csv", "r", newline="") as fp:
      reader = csv.reader(fp)
      for line in reader:
          line = [name.strip() for name in line if name.strip()]
          if len(line) == 1:
              grid[line[0], line[0]] += 1
  
  relations = sorted(set(pair[0] for pair in grid))
  
  with open("color_sorted.csv", "w", newline="") as fp:
      writer = csv.writer(fp)
      writer.writerow([''] + relations)
      for relation in relations:
          line = [relation,] + [grid[relation, other] for other in relations]
          writer.writerow(line)
  </code></pre>