Building graph from string in pythonCalling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Converting string into datetimeDoes Python have a string 'contains' substring method?How do I lowercase a string in Python?Pythonic way to create a long multi-line string
How can Republicans who favour free markets, consistently express anger when they don't like the outcome of that choice?
Extension of 2-adic valuation to the real numbers
"Hidden" theta-term in Hamiltonian formulation of Yang-Mills theory
What happens to Mjolnir (Thor's hammer) at the end of Endgame?
Did the BCPL programming language support floats?
What makes accurate emulation of old systems a difficult task?
Minor Revision with suggestion of an alternative proof by reviewer
Why did some of my point & shoot film photos come back with one third light white or orange?
What happened to Captain America in Endgame?
Retract an already submitted recommendation letter (written for an undergrad student)
Constructions of PRF (Pseudo Random Function)
Check if a string is entirely made of the same substring
Elements that can bond to themselves?
Function pointer with named arguments?
Can SQL Server create collisions in system generated constraint names?
Checks user level and limit the data before saving it to mongoDB
Is Diceware more secure than a long passphrase?
How to pronounce 'c++' in Spanish
Why was the Spitfire's elliptical wing almost uncopied by other aircraft of World War 2?
Contradiction proof for inequality of P and NP?
How come there are so many candidates for the 2020 Democratic party presidential nomination?
Can someone publish a story that happened to you?
How do I reattach a shelf to the wall when it ripped out of the wall?
Can't get 5V 3A DC constant
Building graph from string in python
Calling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Converting string into datetimeDoes Python have a string 'contains' substring method?How do I lowercase a string in Python?Pythonic way to create a long multi-line string
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have a csv file that looks like this:
No String
1 A B A A B C D E E C F
1 B B B C M F G
1 A A M V
2 H C A A A B B N M F
2 N M H D D B A F F N M N
3 A C M G F F A A A
.. ....
I would like to convert this file to a graph where it contains nodes: A,B ,C,D,E,F,G,H,M,N,V and edges between them are the value in column 'No' with considering of loop.
Any hints would be appreciated.
python graph networkx
add a comment |
I have a csv file that looks like this:
No String
1 A B A A B C D E E C F
1 B B B C M F G
1 A A M V
2 H C A A A B B N M F
2 N M H D D B A F F N M N
3 A C M G F F A A A
.. ....
I would like to convert this file to a graph where it contains nodes: A,B ,C,D,E,F,G,H,M,N,V and edges between them are the value in column 'No' with considering of loop.
Any hints would be appreciated.
python graph networkx
add a comment |
I have a csv file that looks like this:
No String
1 A B A A B C D E E C F
1 B B B C M F G
1 A A M V
2 H C A A A B B N M F
2 N M H D D B A F F N M N
3 A C M G F F A A A
.. ....
I would like to convert this file to a graph where it contains nodes: A,B ,C,D,E,F,G,H,M,N,V and edges between them are the value in column 'No' with considering of loop.
Any hints would be appreciated.
python graph networkx
I have a csv file that looks like this:
No String
1 A B A A B C D E E C F
1 B B B C M F G
1 A A M V
2 H C A A A B B N M F
2 N M H D D B A F F N M N
3 A C M G F F A A A
.. ....
I would like to convert this file to a graph where it contains nodes: A,B ,C,D,E,F,G,H,M,N,V and edges between them are the value in column 'No' with considering of loop.
Any hints would be appreciated.
python graph networkx
python graph networkx
asked Dec 9 '18 at 15:38
H.EH.E
253
253
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I just saw your question while browsing it may be late but it maybe helpful
First create one digraph and a list
Graph = DiGraph()
string_list = list # to add all strings
so first you have to read the file and put it in any data structure you prefer. In this case I put it in dictionary
with open(file_path, 'r', encoding='utf-8') as csvfile:
reader = DictReader(csvfile)
data = [dict(x) for x in reader]
after that
for row in data: # for each item in the dictionary
string_list.extend(row['String'].split(' ')) # add a list of strings which are separated by "space" into a list. So that, you can access each character
for char in string_list: # for each element in the list (each character)
Graph.add_edge(row['No'], char) (create an edge between each "No" with each character )
print(Graph.edges())
this should work
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53693898%2fbuilding-graph-from-string-in-python%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I just saw your question while browsing it may be late but it maybe helpful
First create one digraph and a list
Graph = DiGraph()
string_list = list # to add all strings
so first you have to read the file and put it in any data structure you prefer. In this case I put it in dictionary
with open(file_path, 'r', encoding='utf-8') as csvfile:
reader = DictReader(csvfile)
data = [dict(x) for x in reader]
after that
for row in data: # for each item in the dictionary
string_list.extend(row['String'].split(' ')) # add a list of strings which are separated by "space" into a list. So that, you can access each character
for char in string_list: # for each element in the list (each character)
Graph.add_edge(row['No'], char) (create an edge between each "No" with each character )
print(Graph.edges())
this should work
add a comment |
I just saw your question while browsing it may be late but it maybe helpful
First create one digraph and a list
Graph = DiGraph()
string_list = list # to add all strings
so first you have to read the file and put it in any data structure you prefer. In this case I put it in dictionary
with open(file_path, 'r', encoding='utf-8') as csvfile:
reader = DictReader(csvfile)
data = [dict(x) for x in reader]
after that
for row in data: # for each item in the dictionary
string_list.extend(row['String'].split(' ')) # add a list of strings which are separated by "space" into a list. So that, you can access each character
for char in string_list: # for each element in the list (each character)
Graph.add_edge(row['No'], char) (create an edge between each "No" with each character )
print(Graph.edges())
this should work
add a comment |
I just saw your question while browsing it may be late but it maybe helpful
First create one digraph and a list
Graph = DiGraph()
string_list = list # to add all strings
so first you have to read the file and put it in any data structure you prefer. In this case I put it in dictionary
with open(file_path, 'r', encoding='utf-8') as csvfile:
reader = DictReader(csvfile)
data = [dict(x) for x in reader]
after that
for row in data: # for each item in the dictionary
string_list.extend(row['String'].split(' ')) # add a list of strings which are separated by "space" into a list. So that, you can access each character
for char in string_list: # for each element in the list (each character)
Graph.add_edge(row['No'], char) (create an edge between each "No" with each character )
print(Graph.edges())
this should work
I just saw your question while browsing it may be late but it maybe helpful
First create one digraph and a list
Graph = DiGraph()
string_list = list # to add all strings
so first you have to read the file and put it in any data structure you prefer. In this case I put it in dictionary
with open(file_path, 'r', encoding='utf-8') as csvfile:
reader = DictReader(csvfile)
data = [dict(x) for x in reader]
after that
for row in data: # for each item in the dictionary
string_list.extend(row['String'].split(' ')) # add a list of strings which are separated by "space" into a list. So that, you can access each character
for char in string_list: # for each element in the list (each character)
Graph.add_edge(row['No'], char) (create an edge between each "No" with each character )
print(Graph.edges())
this should work
answered Mar 22 at 17:30
HizClickHizClick
157
157
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53693898%2fbuilding-graph-from-string-in-python%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown