Assume that the Gfollowing identifier is specified for the network (Node ID, number of links) and indicate that you want to reset it to the Pandas DataFrame:
import pandas as pd
import networkx as nx
degree=pd.DataFrame({'Node ID':G.degree().keys(),'Degree':G.degree().values()})
degree=degree[['Node ID','Degree']]
You get this:
In[1]: degree.head(5)
Out[1]:
Node ID Degree
0 0 19
1 1 117
2 2 13
3 3 56
4 4 15
Now say that you want to sort this DataFrame relative to the Degree column in descending order. If i do it
sort_degree=degree.sort_values(['Node ID', 'Degree'], ascending=[False, False], inplace=False)
I do not get what I want:
Node ID Degree
4 4 15
3 3 56
2 2 13
1 1 117
0 0 19
What's wrong?
source
share