1

Using Python 3.2 I am trying to turn data from a CSV file into a two-mode network. For those who do not know what that means, the idea is simple:

This is a snippet of my dataset:

Project_ID    Name_1    Name_2    Name_3    Name_4 ... Name_150
    1           Jean      Mike
    2           Mike
    3           Joe       Sarah     Mike      Jean        Nick
    4           Sarah     Mike
    5           Sarah     Jean      Mike      Joe

I want to create a CSV that puts the Project_IDs across the first row of the CSV and each unique name down the first column (with cell A1 blank) and then a 1 in the i,j cell if that person worked on a given project. NOTE: My data has full names (with middle initial), with no two people having the same name so there will not be any duplicates.

The final data output would look like this:

            1             2              3              4              5 
Jean        1             0              1              0              1
Mike        1             1              1              1              1
Joe         0             0              1              0              1
Sarah       0             0              1              1              1
...        ...           ...            ...            ...            ...
Nick        0             0              1              0              0
CJ12
  • 487
  • 2
  • 10
  • 28

1 Answers1

0

Start by using the CVS reader

import csv

with open('some.csv', 'rb') as f:
    reader = csv.reader(f)
    for row in reader:
        print row

Note that row will read as arrays for each line.

The output array should probably be created before you start. As from this question, here is how you could do that

buckets = [[0 for col in range(5)] for row in range(10)]
Community
  • 1
  • 1
PearsonArtPhoto
  • 38,970
  • 17
  • 111
  • 142