How do I store my scraped values into a dataframe once all the pages are looped and values append into my lists?










1















Currently, my dataframe is printing out 2 dataframes but I want it to simply be one dataframe with all the values passed on from omp_name_lists and comp_rating_lists. I know the function is passing values page by page so I would like to know how can I tell python wait for all the page values to append and then create_dataframe.



def get_data(get_comp_name,get_comp_rating):


comp_name_lists, comp_rating_lists = ,
for i, v in zip(get_comp_name, get_comp_rating):
comp_name_lists.append(i.a.text)
comp_rating_lists.append(v.text)

return create_dataframe(comp_name_lists,comp_rating_lists)

def create_dataframe(comp_name_lists,comp_rating_lists): # This is where
"""This gets all of our data that we scraped and stores into a pandas dataframe"""
df = pd.DataFrame('CompanyName' : comp_name_lists, 'CompanyRating' : comp_rating_lists)
df = df.reset_index(drop=True)
print(df)


Desired Output:



 A B
0 a 3
1 b 7
2 c 1
3 d 2
4 e 8
5 f 9
6 g 7
7 h 8









share|improve this question




























    1















    Currently, my dataframe is printing out 2 dataframes but I want it to simply be one dataframe with all the values passed on from omp_name_lists and comp_rating_lists. I know the function is passing values page by page so I would like to know how can I tell python wait for all the page values to append and then create_dataframe.



    def get_data(get_comp_name,get_comp_rating):


    comp_name_lists, comp_rating_lists = ,
    for i, v in zip(get_comp_name, get_comp_rating):
    comp_name_lists.append(i.a.text)
    comp_rating_lists.append(v.text)

    return create_dataframe(comp_name_lists,comp_rating_lists)

    def create_dataframe(comp_name_lists,comp_rating_lists): # This is where
    """This gets all of our data that we scraped and stores into a pandas dataframe"""
    df = pd.DataFrame('CompanyName' : comp_name_lists, 'CompanyRating' : comp_rating_lists)
    df = df.reset_index(drop=True)
    print(df)


    Desired Output:



     A B
    0 a 3
    1 b 7
    2 c 1
    3 d 2
    4 e 8
    5 f 9
    6 g 7
    7 h 8









    share|improve this question


























      1












      1








      1








      Currently, my dataframe is printing out 2 dataframes but I want it to simply be one dataframe with all the values passed on from omp_name_lists and comp_rating_lists. I know the function is passing values page by page so I would like to know how can I tell python wait for all the page values to append and then create_dataframe.



      def get_data(get_comp_name,get_comp_rating):


      comp_name_lists, comp_rating_lists = ,
      for i, v in zip(get_comp_name, get_comp_rating):
      comp_name_lists.append(i.a.text)
      comp_rating_lists.append(v.text)

      return create_dataframe(comp_name_lists,comp_rating_lists)

      def create_dataframe(comp_name_lists,comp_rating_lists): # This is where
      """This gets all of our data that we scraped and stores into a pandas dataframe"""
      df = pd.DataFrame('CompanyName' : comp_name_lists, 'CompanyRating' : comp_rating_lists)
      df = df.reset_index(drop=True)
      print(df)


      Desired Output:



       A B
      0 a 3
      1 b 7
      2 c 1
      3 d 2
      4 e 8
      5 f 9
      6 g 7
      7 h 8









      share|improve this question
















      Currently, my dataframe is printing out 2 dataframes but I want it to simply be one dataframe with all the values passed on from omp_name_lists and comp_rating_lists. I know the function is passing values page by page so I would like to know how can I tell python wait for all the page values to append and then create_dataframe.



      def get_data(get_comp_name,get_comp_rating):


      comp_name_lists, comp_rating_lists = ,
      for i, v in zip(get_comp_name, get_comp_rating):
      comp_name_lists.append(i.a.text)
      comp_rating_lists.append(v.text)

      return create_dataframe(comp_name_lists,comp_rating_lists)

      def create_dataframe(comp_name_lists,comp_rating_lists): # This is where
      """This gets all of our data that we scraped and stores into a pandas dataframe"""
      df = pd.DataFrame('CompanyName' : comp_name_lists, 'CompanyRating' : comp_rating_lists)
      df = df.reset_index(drop=True)
      print(df)


      Desired Output:



       A B
      0 a 3
      1 b 7
      2 c 1
      3 d 2
      4 e 8
      5 f 9
      6 g 7
      7 h 8






      python python-3.x web-scraping beautifulsoup request






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 19:47







      g_altobelli

















      asked Nov 12 '18 at 20:12









      g_altobellig_altobelli

      877




      877






















          1 Answer
          1






          active

          oldest

          votes


















          1














          If you want to be one dataframe with all the values, so you should have a global variable
          because it will be not re-initialize, unless you restart script. If you pass value by return create_dataframe(comp_name_lists,comp_rating_lists), it will create a new space which independent from the others and the value of df is empty that mean you can not done what you expect in this way. In my consideration, create a dataframe after you finished fetching data



          resultset = 'CompanyName' : , 'CompanyRating' : 

          def get_data(get_comp_name,get_comp_rating):


          comp_name_lists, comp_rating_lists = ,
          for i, v in zip(get_comp_name, get_comp_rating):
          comp_name_lists.append(i.a.text)
          comp_rating_lists.append(v.text)

          resultset["CompanyName"] += comp_name_lists
          resultset["CompanyRating"] += comp_rating_lists

          def create_dataframe(data): # This is where
          """This gets all of our data that we scraped and stores into a pandas dataframe"""
          df = pd.DataFrame(data)
          df = df.reset_index(drop=True)
          print(df)





          share|improve this answer























          • Thank you so much! Dam global vars when I need them I never use them lol.

            – g_altobelli
            Nov 13 '18 at 9:15










          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%2f53269411%2fhow-do-i-store-my-scraped-values-into-a-dataframe-once-all-the-pages-are-looped%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









          1














          If you want to be one dataframe with all the values, so you should have a global variable
          because it will be not re-initialize, unless you restart script. If you pass value by return create_dataframe(comp_name_lists,comp_rating_lists), it will create a new space which independent from the others and the value of df is empty that mean you can not done what you expect in this way. In my consideration, create a dataframe after you finished fetching data



          resultset = 'CompanyName' : , 'CompanyRating' : 

          def get_data(get_comp_name,get_comp_rating):


          comp_name_lists, comp_rating_lists = ,
          for i, v in zip(get_comp_name, get_comp_rating):
          comp_name_lists.append(i.a.text)
          comp_rating_lists.append(v.text)

          resultset["CompanyName"] += comp_name_lists
          resultset["CompanyRating"] += comp_rating_lists

          def create_dataframe(data): # This is where
          """This gets all of our data that we scraped and stores into a pandas dataframe"""
          df = pd.DataFrame(data)
          df = df.reset_index(drop=True)
          print(df)





          share|improve this answer























          • Thank you so much! Dam global vars when I need them I never use them lol.

            – g_altobelli
            Nov 13 '18 at 9:15















          1














          If you want to be one dataframe with all the values, so you should have a global variable
          because it will be not re-initialize, unless you restart script. If you pass value by return create_dataframe(comp_name_lists,comp_rating_lists), it will create a new space which independent from the others and the value of df is empty that mean you can not done what you expect in this way. In my consideration, create a dataframe after you finished fetching data



          resultset = 'CompanyName' : , 'CompanyRating' : 

          def get_data(get_comp_name,get_comp_rating):


          comp_name_lists, comp_rating_lists = ,
          for i, v in zip(get_comp_name, get_comp_rating):
          comp_name_lists.append(i.a.text)
          comp_rating_lists.append(v.text)

          resultset["CompanyName"] += comp_name_lists
          resultset["CompanyRating"] += comp_rating_lists

          def create_dataframe(data): # This is where
          """This gets all of our data that we scraped and stores into a pandas dataframe"""
          df = pd.DataFrame(data)
          df = df.reset_index(drop=True)
          print(df)





          share|improve this answer























          • Thank you so much! Dam global vars when I need them I never use them lol.

            – g_altobelli
            Nov 13 '18 at 9:15













          1












          1








          1







          If you want to be one dataframe with all the values, so you should have a global variable
          because it will be not re-initialize, unless you restart script. If you pass value by return create_dataframe(comp_name_lists,comp_rating_lists), it will create a new space which independent from the others and the value of df is empty that mean you can not done what you expect in this way. In my consideration, create a dataframe after you finished fetching data



          resultset = 'CompanyName' : , 'CompanyRating' : 

          def get_data(get_comp_name,get_comp_rating):


          comp_name_lists, comp_rating_lists = ,
          for i, v in zip(get_comp_name, get_comp_rating):
          comp_name_lists.append(i.a.text)
          comp_rating_lists.append(v.text)

          resultset["CompanyName"] += comp_name_lists
          resultset["CompanyRating"] += comp_rating_lists

          def create_dataframe(data): # This is where
          """This gets all of our data that we scraped and stores into a pandas dataframe"""
          df = pd.DataFrame(data)
          df = df.reset_index(drop=True)
          print(df)





          share|improve this answer













          If you want to be one dataframe with all the values, so you should have a global variable
          because it will be not re-initialize, unless you restart script. If you pass value by return create_dataframe(comp_name_lists,comp_rating_lists), it will create a new space which independent from the others and the value of df is empty that mean you can not done what you expect in this way. In my consideration, create a dataframe after you finished fetching data



          resultset = 'CompanyName' : , 'CompanyRating' : 

          def get_data(get_comp_name,get_comp_rating):


          comp_name_lists, comp_rating_lists = ,
          for i, v in zip(get_comp_name, get_comp_rating):
          comp_name_lists.append(i.a.text)
          comp_rating_lists.append(v.text)

          resultset["CompanyName"] += comp_name_lists
          resultset["CompanyRating"] += comp_rating_lists

          def create_dataframe(data): # This is where
          """This gets all of our data that we scraped and stores into a pandas dataframe"""
          df = pd.DataFrame(data)
          df = df.reset_index(drop=True)
          print(df)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 8:44









          kcorlidykcorlidy

          2,2102418




          2,2102418












          • Thank you so much! Dam global vars when I need them I never use them lol.

            – g_altobelli
            Nov 13 '18 at 9:15

















          • Thank you so much! Dam global vars when I need them I never use them lol.

            – g_altobelli
            Nov 13 '18 at 9:15
















          Thank you so much! Dam global vars when I need them I never use them lol.

          – g_altobelli
          Nov 13 '18 at 9:15





          Thank you so much! Dam global vars when I need them I never use them lol.

          – g_altobelli
          Nov 13 '18 at 9:15

















          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%2f53269411%2fhow-do-i-store-my-scraped-values-into-a-dataframe-once-all-the-pages-are-looped%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

          Use pre created SQLite database for Android project in kotlin

          Darth Vader #20

          Ondo