将 Pandas DataFrame 转换为 igraph

问题描述

我想从 excel 中读取并在 igraph 中使用输出。我的代码是:

import igraph as ig import pandas as pd
data=pd.read_excel(r'example.xlsx')
df=pd.DataFrame(data,columns=['product'])
g=ig.Graph.TupleList(df.itertuples(index=False),directed=True)
print(g)

我有这个错误

edge_list.append((idgen[item[0]],idgen[item[1]])) IndexError: tuple
index out of range

我的excel图表是:

Product               Price
desktop computer      700
laptop                250
printer               120
tablet                1200

我使用 pycharm。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)