I need to create a binary matrix
Example Data in a pandas DataFrame
ID P
2 1
1 2
3 2
1 3
1 4
2 5
3 5
Using
A = pd.DataFrame(index=df.ID.values, columns=df.P.values,
data=(df.P.values == df.P.values[:,None]).astype(int))
My current output
Which is correct in terms of where the '1's' hit, but I just want to have the column / row numbers consolidated and the row numbers in order as in:
index 1 2 3 4 5 6 7
1 0 1 1 1 0 1 0
2 1 0 0 0 1 0 1
3 0 1 0 1 1 1 0
If that's not clear, feel free to question!
