在python中的networkx图中查找最大加权边 [英] Finding maximum weighted edge in a networkx graph in python

查看:485
本文介绍了在python中的networkx图中查找最大加权边的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在networkx图中找到'n'个最大加权边.如何实现.我构造了一个图,如下所示:

I want to find 'n' maximum weighted edges in a networkx graph. How can it be achieved. I have constructed a graph as follows :

g_test = nx.from_pandas_edgelist(new_df, 'number', 'contactNumber', edge_attr='callDuration')

现在,我想找到前'n'个边缘权重,即前'n'个callDurations.我还想分析该图以从中找到趋势.请帮助我如何做到这一点.

Now, I want to find top 'n' edge weights, i.e. top 'n' callDurations. I also want to analyse this graph to find trends from it. Please help me how can this be achieved.

推荐答案

如果图形存储为g,则可以使用以下命令访问其边缘,包括其属性:

If your graph is stored as g you can access its edges, including their attributes using:

g.edges(data=True)

这将返回一个元组列表.前两个条目是节点,第三个条目是属性的字典,如下所示:

This returns a list of tuples. The first two entries are the nodes, and the third entry is a dictionary of the attributes, looking like this:

[(a,b,{"callDuration":10}),(a,c,{"callDuration":7})]

您可以像下面这样根据callDuration属性对该列表进行排序:

You can sort this list based the callDuration attribute like this:

sorted(g.edges(data=True),key= lambda x: x[2]['callDuration'],reverse=True)

请注意,我们使用反向按钮首先查看最大的callDuration边缘.

Note we use reverse to see the largest callDuration edges first.

恐怕您的第二个问题很广泛-您可以通过网络来做很多事情!看看像这样的一些教程: https://programminghistorian.org/en/lessons/用python探索和分析网络数据

I'm afraid your second question is very broad - you can do a lot of things with networks! Have a look at some tutorials like this one: https://programminghistorian.org/en/lessons/exploring-and-analyzing-network-data-with-python

这篇关于在python中的networkx图中查找最大加权边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆