I have some data in excel which represents information about a graph and it looks like this:
1 2 4.5
1 3 6.6
2 4 7.3
3 4 5.1
The first two elements in each row are edges of the graph and the last element is the weight of the arc between those two edges. For example, edge "1" is connected to edge "2" and the weight is 4.5
I import this data into python by the following code:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
training_data_x = pd.read_excel("/Users/mac/Downloads/navid.xlsx",header=None)
x= training_data_x.as_matrix()
So "x" here is the adjacency matrix of the graph. What I am trying to do is converting x to list of dictionaries in python which I need in another code. I am kind of new to python but I think a dictionary that suits here kind of looks like this
gr = {'1': {'2': 4.5, '3': 6.6},
'2': {'4': 7.3},
'3': {'4':5.1}}
In fact "gr" should be output of my code here. I think I should use ""pandas.DataFrame.to_dict"' but I have hard time using this command. I really appreciate your help here.
xis actually an adjacency matrix, as it is commonly understood.