我在 python 的数据框中得到了一个邻接矩阵,用于可达性 HW 我的部分硬件是检查解决方案是否正确 所以我的想法是改变细胞的颜色:
if adjM[vi][vj] == 1:
df.iloc[vi,vj] #changeColor(green)
df.iloc[vi,vj] #changeColor(red)
但我只找到穿过所有细胞的函数
有没有办法只改变我用 iloc 得到的细胞?
我找到了
def checkSolution(x):
df = x.copy()
for index, elem in enumerate(solution[:-1]):
if adyacencyM[elem,solution[index+1]] == 1:
df.iloc[elem,solution[index+1]] = 'background-color: green'
df.iloc[elem,solution[index+1]] = 'background-color: red'
return df
strSolChecked = strAdjM.style.apply(checkSolution, axis=None)
strSolChecked
但我什么都没有