2

I don’t have experience with Python/NetworkX. Everything I try is a dead-end. I have Python 2.7 installed on Windows 8. (Took forever to install NetworkX.)

A. I cannot get NetworkX to read my weighted network

I have a text file with the edges and weights, like this:

1 2 2

2 3 1

2 4 1

4 5 4    (…etc.)

I name the file test.edgelist (exactly as I’ve seen in many examples) and then used this code to read it:

import networkx as nx
fh=open("test.edgelist", 'rb')
G=nx.read_weighted_edgelist(fh, nodetype=int)
fh.close()

I get the following error message:

'module' object has no attribute 'read_weighted_edgelist'

(note: for the unweighted version with just the first two columns, using the same code, only with read_edgelist instead of read_weighted_edgelist, it’s working just fine)

And by using this alternative code:

G = nx.read_edgelist("test.edgelist", nodetype=int, data=(("weight",float),))

I get the following error message:

read_edgelist() got an unexpected keyword argument 'data'

B. Can't find a way to read some node attributes from a file.

The text file will be something like:

Label Sex Country Colour

1 F GB green

2 M DE red

3 M IT blue (…etc.)

I found this, which I think is the only remotely relevant to what I’m looking for:

Reading nodes with pos attribute from file in networkx

Although csv format is not the problem in my case, I took a shot and installed pandas, but all I get is errors:

from pandas.io.api import *

from pandas.io.gbq import read_gbq

import pkg_resources
ImportError: No module named pkg_resources
4

1 に答える 1