I have a csv file, which has two columns, including the School ID and the region they belong to:
School ID Area Code
123 1
124 1
125 2
134 2
197 3
212 4
I want to make a region matrix out of it, which gives the value "1" if the belong to same region, and "0" if they don't , kind of like this:
123 124 125 134 197 212
123 1 1 0 0 0 0
124 1 1 0 0 0 0
125 0 0 1 1 0 0
134 0 0 1 1 0 0
197 0 0 0 0 1 1
212 0 0 0 0 1 1
I tried with iterating in the entire csv file:
for i in range(num_schools):
for j in range(num_schools):
if df['Area Code'] != df['Area Code']:
c[i][j] = 0
else:
c[i][j] = 1
The problem is, I dont know how iterate in the csv file, I know I have to change the "if" command, but I am not sure how? Kindly guide me!