0

My graph seems not correctly showing edge attributes (they should assign a weight to the edge). Also, I am getting the following error when I try to associate node's size with their degree.

An example of data is:

Node1   Node2    Edge_Weight    Number
A         B         0.2           1
A         D         0.4           1
A         N         0.1           1
B         C         0.5           1
B         A         0.3           1 
S         X         0.2           1
B         N         0.1           2 
S         C         0.5           2
N         A         0.3           2
S         X         0.2           2

What I have done so far is defining a function that goes through the two files as follows:

def loop_func(df):
    node_list=[]

    G = nx.from_pandas_edgelist(file, source='Node1', target='Node2', edge_attr='Edge_Weight') 
    d = nx.degree(G)
    
    for x in (df.Number.unique()):
        df_num = df[df['Number'] == x]
        graphs = [nx.from_pandas_edgelist(df_num, source='Node1', target='Node2', edge_attr='Edge_Weight') for _ in df.Number.unique()]

        nx.draw_networkx(graphs[x-1])
        plt.show()

    

This code generates the error: AttributeError: 'DegreeView' object has no attribute 'keys' . For sure there is something wrong in assign degree to nodes.

Math
  • 109
  • 2
  • 14
  • 1
    There's not enough code here to reproduce this error. Could you provide a longer, self-contained version of this code segment that does produce this error? It looks like you've assigned the `'Edge_Weight'` values correctly as attributes, but `nx.draw_networkx()` will not automatically draw edge widths unless without passing the `width` parameter to the appropriate drawing function. [This SO question](https://stackoverflow.com/questions/25639169/networkx-change-color-width-according-to-edge-attributes-inconsistent-result) can give you a good idea of how edge widths are typically plotted. – Frodnar Oct 10 '21 at 00:15

0 Answers0