ashutosh
(ashutosh)
July 18, 2018, 7:37am
1
Hi,
I'm trying to convert two columns of my pandas dataframe into network using
them as edge list.
A similar query
<https://stackoverflow.com/questions/35459597/graph-tool-reading-edge-lists-from-pandas-dataframe> ;
was posted in StackOverflow but with different problem and it didn't help
me.
When I am trying the following code it gives me error:
tiago
(Tiago Peixoto)
July 18, 2018, 11:09am
2
Without a minimal and self-contained example that shows the problem, it's
difficult to say anything.
Please provide a small example that we can run, so we can understand what
the problem may be.
solstag
(Ale Abdo)
July 18, 2018, 11:18am
3
Ni! Hi ashu,
Please, always try to *read errors carefully* and consult the
documentation. Not to mention, provide self-contained examples.
Python is throwing a "TypeError" and telling you it expects an integer
('unsigned long', the C++ type for vertex indices) while you are passing it
a string ('str').
As you can see in the documentation
<https://graph-tool.skewed.de/static/doc/graph_tool.html> , if you want to
pass strings to add_edge_list you should set two additional arguments:
`hash=True` and `string_vals=True`.
If that doesn't fix it, you'll have to provide a self-contained example
where the error occurs, otherwise we can't really help.
.~ยด
attachment.html (3.01 KB)
solstag
(Ale Abdo)
July 18, 2018, 11:23am
4
Tiny typo, the first argument is `hashed=True`.
attachment.html (3.5 KB)
ashutosh
(ashutosh)
July 18, 2018, 11:24am
5
sampleFile.tab
<http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/file/t496073/sampleFile.tab> ;
above is the sample file.
and below is the code that produces the error as i mentioned before
import pandas as pd
import graph_tool.all as gtx
df = pd.read_csv("file_path",sep='\t',headers=True)
myGraph = gtx.Graph()
myGraph.add_edge_list(df.values.tolist())
ashutosh
(ashutosh)
July 18, 2018, 11:33am
6
I got the problem.
Graph Tool by default accepts only vertex objects or int(index) values on
edge list and hence either I pass on vertex object list or keep the options*
hashed=True and string_vals=True* in the add_edge_list option.
The problem is resolved now. Thank you