Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NetworkX From_Pandas_dataframe

I have an error with NetworkX which says 'module' has no attribute 'from_pandas_dataframe.'

I have a dataframe called nflroster that is format as:

Index   . . . Player           Team       Year

0       . . . Player1          Team1      2014

1       .  . .Player2          Team1      2014


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

So according to the documentation here networkx documentation this following line should work

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

However when I run this in Ipy notebook I run into the error, 'module' object has no attribute 'from_pandas_dataframe'.

I import the following

import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
import pandas as pd
from pandas import DataFrame as df
like image 295
user2723240 Avatar asked May 04 '15 23:05

user2723240


2 Answers

I had the same problem here. This is how I solved it:

Try installing networkx from source instead of installing it through pip.

Source Install Step by Step

    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

Notice that this specific function From_Pandas_dataframe will be installed in convert_matrix.py file at the networkx folder.

like image 102
Gustavo Avila Avatar answered Sep 27 '22 21:09

Gustavo Avila


You probably installed an incorrect version of networkx. You probably should check whether you have 1.10.0 <= see history here

like image 31
hlin117 Avatar answered Sep 27 '22 22:09

hlin117