title: Create new column with loc() iloc() and apply after using groupby see pictures
body: <p>Given this code:</p>
  <pre><code>from bs4 import BeautifulSoup
  from lxml import etree
  import requests
  import pandas as pd
    
  URL = &quot;https://boards.4chan.org/x/archive&quot;
    
  HEADERS = ({'User-Agent':
              'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 \
              (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36',\
              'Accept-Language': 'en-US, en;q=0.5'})
    
  webpage = requests.get(URL, headers=HEADERS)
  soup = BeautifulSoup(webpage.content, &quot;html.parser&quot;)
  dom = etree.HTML(str(soup))
  
  threads = dom.xpath('//tbody/tr')[0:2]
  print(len(threads))
  threads_count = 0
  rows = []
  
  for i in threads:
    thread_ids = i.xpath('.//td[1]')
  
    for j in thread_ids: 
      thread_id = j.text
  
      threads_count += 1 
      print(f&quot;Currently checking ID = {threads_count}/{(len(threads))}&quot;, end=&quot;&quot;)
      url2 = (f'https://boards.4chan.org/x/thread/{thread_id}')
      webpage = requests.get(url2)
      soup = BeautifulSoup(webpage.content, &quot;html.parser&quot;)
      dom = etree.HTML(str(soup))
  
      threads_containers = dom.xpath('//div[contains(@class,&quot;Container&quot;)]')
  
      for x in threads_containers:
        post_id = x.xpath('.//span[@class=&quot;postNum desktop&quot;]/a[@title=&quot;Reply to this post&quot;]')[0].text
        content = x.xpath('.//blockquote[@class=&quot;postMessage&quot;]/descendant::text()')
        
        new_content = []
        for el in content:
          if thread_id in el:
            el = el+&quot; (OP)&quot;
            new_content.append(el+&quot;\n&quot;)
          else:
            new_content.append(el+&quot;\n&quot;)
  
        rows.append([thread_id, post_id, ''.join(new_content)])
  
      print(&quot;\r&quot;, end=&quot;&quot;)
  
  df = pd.DataFrame(rows, columns=['Threads IDs', 'Posts IDs', 'Content'])
  df
  </code></pre>
  <p>I get a the following DF (<strong>yours can be different because it scraps &quot;live&quot; archives</strong>):</p>
  <p><a href="https://i.stack.imgur.com/RBboE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RBboE.png" alt="enter image description here" /></a></p>
  <p>Then I use this code:</p>
  <pre><code>df1 = df[['Threads IDs', 'Posts IDs']].groupby('Threads IDs').count().rename(columns={'Posts IDs': 'Number of Posts'})
  df1
  </code></pre>
  <p>to get the following result:</p>
  <p><a href="https://i.stack.imgur.com/fu2Xt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fu2Xt.png" alt="enter image description here" /></a></p>
  <p>Now, what I would like, its creating a third column named &quot;What&quot;, applying the code below but for the entire dataframe:</p>
  <pre><code>df.loc[df['Threads IDs'] == '31904499', 'Content'].iloc[0]
  </code></pre>
  <p>I tried to play with &quot;apply&quot; and the code above, without success.</p>
  <p><strong>If I resume:</strong>
  After using &quot;<em>groupby</em>&quot; to get the new DF with the &quot;<em>Number of Posts</em>&quot; by &quot;<em>Threads IDs</em>&quot;, I would like to create a third column, named &quot;What&quot;, which contains for each row the first value of &quot;Content&quot; ([0]) corresponding to the respective &quot;Thread ID&quot;.</p>