简体   繁体   English

python中的networkx从csv文件中读取

[英]networkx in python reading from csv file

I have a data in csv file and that has following datas in it:我在 csv 文件中有一个数据,其中包含以下数据:

    Origin  Destiny  Hours
0     Alat     Baku   1.08
1     Baku     Alat   1.13
2     Alat  Shirvan   0.83
3  Shirvan     Alat   0.80
4  Imishli  Shirvan   1.42
Index(['Origin', 'Destiny', 'Hours'], dtype='object')

Now when i do现在当我做

G = networkx.from_pandas_edgelist(data, source='Origin', target='Destiny', edge_attr=True)

there happens a problem or a misunderstanding for me: Because both G.edges["Baku","Alat"] and G.edges["Alat","Baku"] gives the same result which is {'Hours': 1.13} .我遇到了一个问题或误解:因为G.edges["Baku","Alat"] G.edges["Alat","Baku"] G.edges["Baku","Alat"]G.edges["Alat","Baku"]给出了相同的结果,即{'Hours': 1.13} . Why is it like this,as it should give 1.08 and 1.13 for reversed order.为什么会这样,因为它应该为相反的顺序提供 1.08 和 1.13。

You should use Directed graphs by using parameter create_using=networkx.DiGraph()您应该通过使用参数create_using=networkx.DiGraph()来使用有向图

G = networkx.from_pandas_edgelist(
    data, source='Origin', target='Destiny', edge_attr=True,
create_using=networkx.DiGraph())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM