Python - How to store values from a while loop into a pandas dataframe?









up vote
1
down vote

favorite
1












I am trying to get the values from my list and store them into a dataframe



while (rank < len(get_rank)) and (summoner_name < len(get_summoner_name)) and (tier < len(get_tier)) and (lp < len(get_LP)) and (wr < len(get_wr)):
contains1 = get_rank[rank]
rank += 1
rank_list = [rank for rank in contains1]
df = pd.DataFrame('A':rank_list[0],index = [0])
print(df)


My rank_listoutputs:



[1]
[2]
[3]


My rank_list[0] outputs:



1
2
3


My current output:



 A
0 1
A
0 2
A
0 3


My desired output:



 A
0 1
1 2
2 3









share|improve this question

























    up vote
    1
    down vote

    favorite
    1












    I am trying to get the values from my list and store them into a dataframe



    while (rank < len(get_rank)) and (summoner_name < len(get_summoner_name)) and (tier < len(get_tier)) and (lp < len(get_LP)) and (wr < len(get_wr)):
    contains1 = get_rank[rank]
    rank += 1
    rank_list = [rank for rank in contains1]
    df = pd.DataFrame('A':rank_list[0],index = [0])
    print(df)


    My rank_listoutputs:



    [1]
    [2]
    [3]


    My rank_list[0] outputs:



    1
    2
    3


    My current output:



     A
    0 1
    A
    0 2
    A
    0 3


    My desired output:



     A
    0 1
    1 2
    2 3









    share|improve this question























      up vote
      1
      down vote

      favorite
      1









      up vote
      1
      down vote

      favorite
      1






      1





      I am trying to get the values from my list and store them into a dataframe



      while (rank < len(get_rank)) and (summoner_name < len(get_summoner_name)) and (tier < len(get_tier)) and (lp < len(get_LP)) and (wr < len(get_wr)):
      contains1 = get_rank[rank]
      rank += 1
      rank_list = [rank for rank in contains1]
      df = pd.DataFrame('A':rank_list[0],index = [0])
      print(df)


      My rank_listoutputs:



      [1]
      [2]
      [3]


      My rank_list[0] outputs:



      1
      2
      3


      My current output:



       A
      0 1
      A
      0 2
      A
      0 3


      My desired output:



       A
      0 1
      1 2
      2 3









      share|improve this question













      I am trying to get the values from my list and store them into a dataframe



      while (rank < len(get_rank)) and (summoner_name < len(get_summoner_name)) and (tier < len(get_tier)) and (lp < len(get_LP)) and (wr < len(get_wr)):
      contains1 = get_rank[rank]
      rank += 1
      rank_list = [rank for rank in contains1]
      df = pd.DataFrame('A':rank_list[0],index = [0])
      print(df)


      My rank_listoutputs:



      [1]
      [2]
      [3]


      My rank_list[0] outputs:



      1
      2
      3


      My current output:



       A
      0 1
      A
      0 2
      A
      0 3


      My desired output:



       A
      0 1
      1 2
      2 3






      python arrays python-3.x pandas






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 10 at 7:10









      g_altobelli

      877




      877






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote













          I believe you can append first value of contains1 to list and then out of loop create DataFrame by contructor:



          L = 
          while (rank < len(get_rank)) and (summoner_name < len(get_summoner_name)) and (tier < len(get_tier)) and (lp < len(get_LP)) and (wr < len(get_wr)):
          rank = get_rank[rank]
          summoner_name = get_summoner_name[rank]
          tier = get_tier[rank]
          lp = get_lp[rank]
          wr = get_wr[rank]
          d = 'rank':rank,
          'summoner_name':summoner_name,
          'tier':tier,
          'lp':lp,
          'wr':wr

          L.append(d)

          df = pd.DataFrame(L)
          print(df)





          share|improve this answer






















          • I figured this would work but I am trying to make it more readable instead of doing this rank_list,summoner_name_list,tier_list,lp_list,wr_list= ,,,,
            – g_altobelli
            Nov 10 at 8:04











          • @g_altobelli - check edited answer, you can create dictionary for each iteration and pass it to list, last pass to DataFrame constructor.
            – jezrael
            Nov 10 at 8:11

















          up vote
          0
          down vote













          df = pd.DataFrame(rank_list[0], columns=['A'])






          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',
            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%2f53236798%2fpython-how-to-store-values-from-a-while-loop-into-a-pandas-dataframe%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote













            I believe you can append first value of contains1 to list and then out of loop create DataFrame by contructor:



            L = 
            while (rank < len(get_rank)) and (summoner_name < len(get_summoner_name)) and (tier < len(get_tier)) and (lp < len(get_LP)) and (wr < len(get_wr)):
            rank = get_rank[rank]
            summoner_name = get_summoner_name[rank]
            tier = get_tier[rank]
            lp = get_lp[rank]
            wr = get_wr[rank]
            d = 'rank':rank,
            'summoner_name':summoner_name,
            'tier':tier,
            'lp':lp,
            'wr':wr

            L.append(d)

            df = pd.DataFrame(L)
            print(df)





            share|improve this answer






















            • I figured this would work but I am trying to make it more readable instead of doing this rank_list,summoner_name_list,tier_list,lp_list,wr_list= ,,,,
              – g_altobelli
              Nov 10 at 8:04











            • @g_altobelli - check edited answer, you can create dictionary for each iteration and pass it to list, last pass to DataFrame constructor.
              – jezrael
              Nov 10 at 8:11














            up vote
            1
            down vote













            I believe you can append first value of contains1 to list and then out of loop create DataFrame by contructor:



            L = 
            while (rank < len(get_rank)) and (summoner_name < len(get_summoner_name)) and (tier < len(get_tier)) and (lp < len(get_LP)) and (wr < len(get_wr)):
            rank = get_rank[rank]
            summoner_name = get_summoner_name[rank]
            tier = get_tier[rank]
            lp = get_lp[rank]
            wr = get_wr[rank]
            d = 'rank':rank,
            'summoner_name':summoner_name,
            'tier':tier,
            'lp':lp,
            'wr':wr

            L.append(d)

            df = pd.DataFrame(L)
            print(df)





            share|improve this answer






















            • I figured this would work but I am trying to make it more readable instead of doing this rank_list,summoner_name_list,tier_list,lp_list,wr_list= ,,,,
              – g_altobelli
              Nov 10 at 8:04











            • @g_altobelli - check edited answer, you can create dictionary for each iteration and pass it to list, last pass to DataFrame constructor.
              – jezrael
              Nov 10 at 8:11












            up vote
            1
            down vote










            up vote
            1
            down vote









            I believe you can append first value of contains1 to list and then out of loop create DataFrame by contructor:



            L = 
            while (rank < len(get_rank)) and (summoner_name < len(get_summoner_name)) and (tier < len(get_tier)) and (lp < len(get_LP)) and (wr < len(get_wr)):
            rank = get_rank[rank]
            summoner_name = get_summoner_name[rank]
            tier = get_tier[rank]
            lp = get_lp[rank]
            wr = get_wr[rank]
            d = 'rank':rank,
            'summoner_name':summoner_name,
            'tier':tier,
            'lp':lp,
            'wr':wr

            L.append(d)

            df = pd.DataFrame(L)
            print(df)





            share|improve this answer














            I believe you can append first value of contains1 to list and then out of loop create DataFrame by contructor:



            L = 
            while (rank < len(get_rank)) and (summoner_name < len(get_summoner_name)) and (tier < len(get_tier)) and (lp < len(get_LP)) and (wr < len(get_wr)):
            rank = get_rank[rank]
            summoner_name = get_summoner_name[rank]
            tier = get_tier[rank]
            lp = get_lp[rank]
            wr = get_wr[rank]
            d = 'rank':rank,
            'summoner_name':summoner_name,
            'tier':tier,
            'lp':lp,
            'wr':wr

            L.append(d)

            df = pd.DataFrame(L)
            print(df)






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 10 at 8:10

























            answered Nov 10 at 7:18









            jezrael

            312k21247323




            312k21247323











            • I figured this would work but I am trying to make it more readable instead of doing this rank_list,summoner_name_list,tier_list,lp_list,wr_list= ,,,,
              – g_altobelli
              Nov 10 at 8:04











            • @g_altobelli - check edited answer, you can create dictionary for each iteration and pass it to list, last pass to DataFrame constructor.
              – jezrael
              Nov 10 at 8:11
















            • I figured this would work but I am trying to make it more readable instead of doing this rank_list,summoner_name_list,tier_list,lp_list,wr_list= ,,,,
              – g_altobelli
              Nov 10 at 8:04











            • @g_altobelli - check edited answer, you can create dictionary for each iteration and pass it to list, last pass to DataFrame constructor.
              – jezrael
              Nov 10 at 8:11















            I figured this would work but I am trying to make it more readable instead of doing this rank_list,summoner_name_list,tier_list,lp_list,wr_list= ,,,,
            – g_altobelli
            Nov 10 at 8:04





            I figured this would work but I am trying to make it more readable instead of doing this rank_list,summoner_name_list,tier_list,lp_list,wr_list= ,,,,
            – g_altobelli
            Nov 10 at 8:04













            @g_altobelli - check edited answer, you can create dictionary for each iteration and pass it to list, last pass to DataFrame constructor.
            – jezrael
            Nov 10 at 8:11




            @g_altobelli - check edited answer, you can create dictionary for each iteration and pass it to list, last pass to DataFrame constructor.
            – jezrael
            Nov 10 at 8:11












            up vote
            0
            down vote













            df = pd.DataFrame(rank_list[0], columns=['A'])






            share|improve this answer
























              up vote
              0
              down vote













              df = pd.DataFrame(rank_list[0], columns=['A'])






              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                df = pd.DataFrame(rank_list[0], columns=['A'])






                share|improve this answer












                df = pd.DataFrame(rank_list[0], columns=['A'])







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 10 at 7:37









                user3665224

                3011316




                3011316



























                    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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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%2f53236798%2fpython-how-to-store-values-from-a-while-loop-into-a-pandas-dataframe%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

                    Kleinkühnau

                    Makov (Slowakei)

                    Deutsches Schauspielhaus