title: My for loop and isn't working and I wonder what happened
body: <p>My goal is to write a function to run multiple times. The input is a dataframe and the output is a dataframe as well. The dataframe is a one-column dataframe. What I am trying to do is extract 10 words from that column each time and store it to a new dataframe. After that run the same function again but this time take out the first word then extract 10 words out from the column and put it to the dataframe that I created before. I was testing out the For Loop to see whether it work or not but for some reason the for loop isn't working. It only run 1 time instead of 3 times. I am wondering am I doing something wrong? And do you guys have a better solution for me to finish the task?</p>
  <p>I will make my task short below for better understanding.</p>
  <ol>
  <li>Extract 10 words from the original dataframe (df)</li>
  <li>Store them into new dataframe (df1)</li>
  <li>Run the function again but this time take out the first word then do the extraction. Store/merge them into df1.</li>
  <li>Need to run multiple times</li>
  </ol>
  <p>So the input dataframe is shown below:</p>
  <pre><code>In [2]: df
  Out [2]:  
  
     text
  0 I love python and I want to learn more and more and more
  1 I do not love python but I want to learn more and more and more
  2 This function is not working and I do not know what to do about it
     :
     :
  n This is the end of the dataframe and I hope you all understand
  </code></pre>
  <p>Here is my code to try to loop multiple times:</p>
  <pre><code>def loop(dataframe):
  
      dataframe = df
     
      for i in range(3):
          
          df.loc[:,'text'] = df['text'].apply(lambda x: ' '.join(x.split()[:10]))
  
          df.loc[:,'text'] = df['text'].apply(lambda x: ' '.join(x.split(' ')[1:]))
          
          df1 = pd.DataFrame(df['text'])
         
          new = [df,df1]
  
          new_df = pd.concat(new)
        
      return new_df
  </code></pre>
  <p>I used 3 times as a text value, but the output wasn't as I expected to be. It showed that I had only run 1 time instead of 3 times. I tried to test this first before doing anything further.</p>
  <p>After the function fully finished, I expect to see something like this below:</p>
  <pre><code>   In [2]: loop(df)
     Out [2]: 
        text
      0 I love python and I want to learn more and more and more
      1 love python and I want to learn more and more and more
      2 python and I want to learn more and more and more
      3 I do not love python but I want to learn more and more and more
      4 do not love python but I want to learn more and more and more
      5 not love python but I want to learn more and more and more
      6 This function is not working and I do not know what to do about it
      7 function is not working and I do not know what to do about it
      8 is not working and I do not know what to do about it
         :
         :
      n the end of the dataframe and I hope you all understand
  </code></pre>
  <p>I am curious did I do something wrong with the code? Or do you guys have any other suggestions for me to do this? Thank you!!!</p>