python – NetworkX From_Pandas_dataframe

我对NetworkX有一个错误,说’模块’没有属性’from_pandas_dataframe’.

我有一个名为nflroster的数据框格式为:

Index   . . . Player           Team       Year

0       . . . Player1          Team1      2014

1       .  . .Player2          Team1      2014


2       . . . Player3          Team2      2014
.
.       . . .   .                .         .

所以根据这里的文档networkx documentation,以下这一行应该有效

G = nx.from_pandas_dataframe(nflroster,str, 'Team')

但是,当我在Ipy笔记本中运行时遇到错误,’module’对象没有属性’from_pandas_dataframe’.

我导入以下内容

import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
import pandas as pd
from pandas import DataFrame as df

最佳答案 我在这里遇到了同样的问题.这就是我解决它的方式:

尝试从源代码安装networkx,而不是通过pip安装.

源安装步骤

    Download the source (tar.gz or zip file) from https://pypi.python.org/pypi/networkx/ or get the latest development version from https://github.com/networkx/networkx/
    Unpack and change directory to the source directory (it should have the files README.txt and setup.py).
    Run python setup.py install to build and install

请注意,此特定函数From_Pandas_dataframe将安装在networkx文件夹的convert_matrix.py文件中.

点赞