熊猫根据列中的顺序分组

时间:2020-04-06 01:22:56

标签: pandas numpy

我的数据(作为熊猫数据框)


Col 1    Col 2     Count    
[12,3]   [12,3]     12 
[12,3]   [12,1]     10
[12,3]   [12,2]     5
[12,1]   [12,0]     4
[12,2]   [12,1]     18    

我有很多这样的组合。我想开发一个转换矩阵和这样的输出

  i,j        [12,0]    [12,1]   [12,2]  [12,3]...................[i,j]
[12,0]       0           0       0       0 .......................0      
[12,1]       4           0       0       0 ......................0 
[12,2]       0           18      0       0 .......................0  
[12,3]       0            5      10      12.......................0   

I have a lot of combinations like this.I want to develop a transition matrix and an output like this 
Have tried this
data.groupby(["col1"])["col2"].count()
but i need help in automating for all ranges in a combination[i,j]

0 个答案:

没有答案