AttributeError:模块"networkx"没有属性"from_pandas_dataframe" [英] AttributeError: module 'networkx' has no attribute 'from_pandas_dataframe'

查看:527
本文介绍了AttributeError:模块"networkx"没有属性"from_pandas_dataframe"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有networkx v. 2.1.为了使其能够与熊猫数据框一起工作,我尝试了以下操作:

I have networkx v. 2.1. to make it work w/ pandas dataframe, i tried following:

  • 是通过pip3安装的,无法像标题中那样生成Atrribute Error,因此已被卸载.
  • 重新安装了'python3 setup.py install"
  • installed via pip3, this did not work generated Atrribute Error as in title, hence uninstalled.
  • re-installed with 'python3 setup.py install"

错误说明.

AttributeError:模块'networkx'没有属性'from_pandas_dataframe`

AttributeError: module 'networkx' has no attribute 'from_pandas_dataframe`

重现错误的步骤:

我使用csv导入了数据.我这样做是因为我只想从数据集中读取5000行.

I imported data using csv. I did this because I just wanted to read only 5000 rows from the dataset.

x=pd.DataFrame([x for x in rawData[:5000]])

x[:10] 

0   1   2
0   228055  231908  1
1   228056  228899  1
2   228050  230029  1
3   228059  230564  1
4   228059  230548  1
5   70175   70227   1
6   89370   236886  1
7   89371   247658  1
8   89371   249558  1
9   89371   175997  1

g_data=G=nx.from_pandas_dataframe(x)

module 'networkx' has no attribute 'from_pandas_dataframe'

我知道我缺少from_pandas_dataframe,但是找不到安装它的方法.

I know I am missing the from_pandas_dataframe but cant find a way to install it.

[m for m in nx.__dir__() if 'pandas' in m] 

['from_pandas_adjacency',
 'to_pandas_adjacency',
 'from_pandas_edgelist',
 'to_pandas_edgelist']

推荐答案

在networkx 2.0中from_pandas_dataframe 已被删除.

In networkx 2.0 from_pandas_dataframe has been removed.

相反,您可以使用 from_pandas_edgelist .

Instead you can use from_pandas_edgelist.

那么您将拥有:

g_data=G=nx.from_pandas_edgelist(x, 1, 2, edge_attr=True)

这篇关于AttributeError:模块"networkx"没有属性"from_pandas_dataframe"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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