我创建了一个矩阵:蟒蛇 - 转换大熊猫矩阵到数据帧
items = [0, 1, 2, 3]
item_to_item = pd.DataFrame(index=items, columns=items)
我已经把值这么:
- 其对称的
- 其对角线为全0
例如:
0 1 2 3
0 0 4 5 9
1 4 0 3 7
2 5 3 0 3
3 9 7 3 0
我要创建的所有可能对的数据帧(来自[0,1,2,3]),以便有不会是对(x, x)
并且如果(x, y)
是,我不想(y, x)
监守其对称的并保持相同的价值。 最后,我将具有以下数据帧(或numpy的2D阵列)
item, item, value
0 1 4
0 2 5
0 3 9
1 2 3
1 3 7
2 3 3
你知道我是如何保持原有IDS?我注意到他们正在改变序列从0到len(项目) –
@EranMoshe如果你的意思是使用行索引,那么你可以这样做:'np.column_stack((item_to_item.index [r],item_to_item.index [c ],..))'。请让我知道这对你有没有用。 – Divakar
伟大的我的朋友! –