I have a data frame as below which is df, the values between the index in columns and rows are weights.
A B B C
B 1 11 ... ..
C 11 2 .. ..
D 10 10
I use this code below for creating graph:
G = nx.from_numpy_matrix(df.values.astype(int))
when I call G2[5]
for example
the result is here {26: {'weight': 1019}, 39: {'weight': 256}, 59: {'weight': 248}}
And then use this for Depth first search
def dfs(graph, start, visited=None):
if visited is None:
visited = set()
visited.add(start)
for next in graph[start] - visited:
dfs(graph, next, visited)
return visited
But I got the error unhashable type: 'dict'
when I called the function with graph G above and start point is G[5] for example dfs(G, G[5])
. Anyone know the reason why because the dfs function work with other graph?