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;








0















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.










share|improve this question




























    0















    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.










    share|improve this question
























      0












      0








      0








      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.










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 9 '18 at 15:38









      H.EH.E

      253




      253






















          1 Answer
          1






          active

          oldest

          votes


















          0














          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






          share|improve this answer























            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
            );



            );













            draft saved

            draft discarded


















            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









            0














            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






            share|improve this answer



























              0














              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






              share|improve this answer

























                0












                0








                0







                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






                share|improve this answer













                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







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 22 at 17:30









                HizClickHizClick

                157




                157





























                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해