I am working on a recommendation project where I have data like this:
ID Movie
1 A
2 B
3 C
4 D
..
..
I want to create this dataframe into a sparse matrix like this:
1 2 3 4 ....n
1 1 0 0 0 0
2 0 1 0 0 0
3 0 0 1 0 0
4 0 0 0 1 0
.
.
n 0 0 0 0 1
Basically both rows and columns contains the ID of the move, and the value is 1 when both row and column element has same value. I want to represent this into a sparse format of
<sparse matrix of type '<class 'numpy.int32'>'
with 58770 stored elements in Compressed Sparse Row format>
I tried doing the following:
- np.diag(items)
- csr_matrix(items.values)
But I am not able to figure it out. Can anyone help me?