I would like to convert a pandas Series into a matrix counting where the same value occurs. Basically the index and columns will be the same and the values in the series will be counted where they occur at the same index. It’s hard for me to explain but this example should illustrate what I’m trying to achieve!
Index | Col Values |
---|---|
1 | 1 |
2 | 2 |
3 | 3 |
4 | 1 |
5 | 2 |
to
Index | 1 | 2 | 3 | 4 | 5 |
---|---|---|---|---|---|
1 | 1 | 0 | 0 | 1 | 0 |
2 | 0 | 1 | 0 | 0 | 1 |
3 | 0 | 0 | 1 | 0 | 0 |
4 | 1 | 0 | 0 | 1 | 0 |
5 | 0 | 1 | 0 | 0 | 1 |
I tried pivot tables, correlation functions but they didn’t work for me (yet?).